警报(” X =” + x)的

编程入门 行业动态 更新时间:2024-10-11 23:25:57
本文介绍了警报(” X =” + x)的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何编写函数f(x)或f(''x''),以便它产生相同的输出 作为对alert-function的调用: var x =''abc''; alert(''x =''+ x); 在测试中,需要经常编写类似的alert()调用。通过使用一个 函数f(),它将在变量 值前面添加变量名称,可以在一个生命周期内节省大量的输入。 我觉得有这么简单的解决方案,我很可能会觉得很尴尬得到答案后尴尬。所以我提前脸红了:)。

How to write a function f(x) or f(''x'') so that it produces the same output as a call to alert-function: var x=''abc''; alert(''x=''+x); In testing one needs to write similar alert() calls often. By having a function f(), which would add the variable name in front of the variable value one would save a lot of typing during one''s lifetime. I think there is so simple solution for this that I probable will feel very embarrassed after getting the answer. So I blush in advance :).

推荐答案

optimistx于2004年4月5日在comp.lang.javascript中写道 : optimistx wrote on 05 apr 2004 in comp.lang.javascript: 如何编写函数f(x)或f(''x''),使其产生与调用alert-function相同的输出: /> var x =''abc''; 警告(''x =''+ x); 在测试中需要写一个类似的alert()经常打电话。通过使用函数f(),它会在变量值前面添加变量名,可以在一个人的生命周期中节省大量的输入。 How to write a function f(x) or f(''x'') so that it produces the same output as a call to alert-function: var x=''abc''; alert(''x=''+x); In testing one needs to write similar alert() calls often. By having a function f(), which would add the variable name in front of the variable value one would save a lot of typing during one''s lifetime.

函数toAlert(x){ alert(''toAlertParameter ="''+ x +''"''); } toAlert(''试试看'') toAlert(355/113) - - Evertjan。 荷兰。 (请在我的电子邮件地址中将x'变为点数)

function toAlert(x){ alert(''toAlertParameter = "''+x+''"''); } toAlert(''Try me out'') toAlert( 355/113) -- Evertjan. The Netherlands. (Please change the x''es to dots in my emailaddress)

" Evertjan。" <前************** @ interxnl> kirjoitti viestiss? 新闻:Xn ******************** @ 194.109.133.29 ... "Evertjan." <ex**************@interxnl> kirjoitti viestiss? news:Xn********************@194.109.133.29... optimistx写于2004年4月5日的comp.lang.javascript : optimistx wrote on 05 apr 2004 in comp.lang.javascript: 如何编写函数f(x)或f(''x'')所以它产生与警报功能相同的输出: var x =''abc''; 警告(''x =' '+ x); 在测试中,需要经常编写类似的alert()调用。通过使用函数f(),它会在变量值前面添加变量名,可以在一个人的生命周期中节省大量的输入。 How to write a function f(x) or f(''x'') so that it produces the same output as a call to alert-function: var x=''abc''; alert(''x=''+x); In testing one needs to write similar alert() calls often. By having a function f(), which would add the variable name in front of the variable value one would save a lot of typing during one''s lifetime.

函数toAlert(x){ alert(''toAlertParameter ="''+ x +''"''); } toAlert(' '试试看'') toAlert(355/113) - Evertjan。荷兰。(请更改x'我的电子邮件地址中的点数。

function toAlert(x){ alert(''toAlertParameter = "''+x+''"''); } toAlert(''Try me out'') toAlert( 355/113) -- Evertjan. The Netherlands. (Please change the x''es to dots in my emailaddress)

感谢Evertjan的尝试。在询问时我可能有点不清楚。 发布后,我无法抗拒试图找到解决方案。一种方法是使用这样的''邪恶''评价函数: alertt = function(){ var s =''''; for(var i = 0; i< arguments.length; i = i + 1){ s + = arguments [i] +''=''+ eval(arguments [i])+''\ n''; } alert(s); } //示例用法: var x = 3; var y =''abc''; alertt(''x'',''y'',''document.title''); //输出是一个警告框,例如: x = 3 y = abc document.title =示例文档标题 和 alertt(''''')提供一个带文字的提示框 x = 3 很抱歉打扰读者可能徒劳无功。希望代码对于 除了我以外的其他人有用:)。 顺便问一下,有没有办法避免上面的eval()? />

Thanks Evertjan for trying. I was probably a bit unclear when asking. After posting I could not resist trying to find a solution anyhow. One way was to use the ''evil'' eval function like this: alertt=function(){ var s=''''; for (var i=0;i<arguments.length;i=i+1){ s+=arguments[i]+''=''+eval(arguments[i])+''\n''; } alert(s); } // example usage: var x=3; var y=''abc''; alertt(''x'',''y'',''document.title''); // the output is an alert box with e.g. x=3 y=abc document.title=example document title and alertt(''x'') gives an alert box with text x=3 Sorry to bother readers perhaps in vain. Hopefully the code is useful for someone else except me :). By the way, is there a way to avoid eval() above?

optimistx于2004年4月5日在comp.lang.javascript中写道 : optimistx wrote on 05 apr 2004 in comp.lang.javascript: By那么,有没有办法避免上面的eval()? By the way, is there a way to avoid eval() above?

总有办法避免邪恶[记得周日学校]: toAlert = function(){ var s =''''; for(var i = 0; i< arguments.length; i ++ ) s + = arguments [i] +''=''+ window [arguments [i]] +''\ n''; alert(s) ; } var x = 5 var y = x * x toAlert(''x' ',''y'') 这只适用于全局变量, 不适用于''document.title'', 也不是''2 * 3 * 4''。 - Evertjan。 荷兰。 (请更改x''我的电子邮件中的点数)

There is always a way to avoid evil [remember sunday school]: toAlert=function(){ var s=''''; for (var i=0;i<arguments.length;i++) s+=arguments[i]+'' = ''+window[arguments[i]]+''\n''; alert(s); } var x=5 var y=x*x toAlert(''x'',''y'') this does only work for global variables, not for ''document.title'', nor for ''2*3*4''. -- Evertjan. The Netherlands. (Please change the x''es to dots in my emailaddress)

更多推荐

警报(” X =” + x)的

本文发布于:2023-11-27 22:16:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!