警报(” X =” + x)的 [英] alert('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.net> kirjoitti viestiss?
新闻:Xn ******************** @ 194.109.133.29 ...
"Evertjan." <ex**************@interxnl.net> 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)的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!