<html>
<head>
<script language="javascript">
function system(a){
this.login=function(){
return(6);
}
}
nnn= function(){}
nnn.prototype=new system();var ttt=new nnn();
var y=1;
eval("var z"+y);
z1=2
alert(eval("z"+y));
a=ttt.login();
alert(a);
alert(typeof(eval("z"+y)));</script>
</head>
<body onload="init()">
<script language="vbscript">
function init()set ttt=document.getElementById("sele1")
For i = 1To 50
Set oOption = document.createElement("OPTION")
oOption.Value = i
oOption.text = i
ttt.Add oOption
Set oOption = Nothing
Next
dim c(),b(2)
redim c(3)
c(0)=1
c(1)=2
b(0)=c(0)
b(1)=c(1)
'erase c
redim c(2)
for i=0 to ubound(b)-1
c(i)=b(i)
next
redim Preserve c(2)
t=ubound(c)
alert(t)
picinfo="aaa"
nnn="aaa_" & "1"
liu="bbb"
str="set " & picinfo & "_1" & "=" & "createobject(" & """" & "scripting.dictionary" & """" & ")"
'str = picinfo & "=" & liu
'str=nnn & "=" & "liu"
'execute("picinfo=liu")
execute(str)
str1=picinfo & "_1" & ".add" & """" & "mmm" & """" & "," & """" & 111 & """"
execute(str1)
msgbox aaa_1("mmm")
'aaa.add "mmm",liu
'kkk=aaa("nnn")
'if len(kkk)=0 then
' msgbox "xxx"
'end if
'alert eval(nnn)
'set execute("picinfo=new jjj")
'set eval("picinfo=createobject(" & """" & "scripting.dictionary" & """" & ")")
'c=b
'a=b
document.write "liuxiaoyi666"
end function
class jjj
end class
</script>
<select id="sele1">
</select>
</body></html>顺便赙赠一些代码了,你说的那个在前面我做完测试了,你就明白为什么是undefine了
<head>
<script language="javascript">
function system(a){
this.login=function(){
return(6);
}
}
nnn= function(){}
nnn.prototype=new system();var ttt=new nnn();
var y=1;
eval("var z"+y);
z1=2
alert(eval("z"+y));
a=ttt.login();
alert(a);
alert(typeof(eval("z"+y)));</script>
</head>
<body onload="init()">
<script language="vbscript">
function init()set ttt=document.getElementById("sele1")
For i = 1To 50
Set oOption = document.createElement("OPTION")
oOption.Value = i
oOption.text = i
ttt.Add oOption
Set oOption = Nothing
Next
dim c(),b(2)
redim c(3)
c(0)=1
c(1)=2
b(0)=c(0)
b(1)=c(1)
'erase c
redim c(2)
for i=0 to ubound(b)-1
c(i)=b(i)
next
redim Preserve c(2)
t=ubound(c)
alert(t)
picinfo="aaa"
nnn="aaa_" & "1"
liu="bbb"
str="set " & picinfo & "_1" & "=" & "createobject(" & """" & "scripting.dictionary" & """" & ")"
'str = picinfo & "=" & liu
'str=nnn & "=" & "liu"
'execute("picinfo=liu")
execute(str)
str1=picinfo & "_1" & ".add" & """" & "mmm" & """" & "," & """" & 111 & """"
execute(str1)
msgbox aaa_1("mmm")
'aaa.add "mmm",liu
'kkk=aaa("nnn")
'if len(kkk)=0 then
' msgbox "xxx"
'end if
'alert eval(nnn)
'set execute("picinfo=new jjj")
'set eval("picinfo=createobject(" & """" & "scripting.dictionary" & """" & ")")
'c=b
'a=b
document.write "liuxiaoyi666"
end function
class jjj
end class
</script>
<select id="sele1">
</select>
</body></html>顺便赙赠一些代码了,你说的那个在前面我做完测试了,你就明白为什么是undefine了
<script language="javascript">
function abc(i){
try
{
alert(typeof(eval("z"+i)));
}
catch(e)
{
alert(e.message);
}
}
abc(1);
</script>
变量定义了是可以得到值的,但我想判断没定义的情况下啊,为什么判断不到?如去掉a=ttt.login();就会出错啊。
//a=ttt.login();
alert(a);
alert(typeof(eval("z"+y)));
var y=1;
eval("var z"+y);
z1=2
alert(eval("z"+y));
alert(typeof(eval("z"+y)));这个是给你的,只有你给了值的时候才是number,没有值的时候当然是undefine,又没有定义过
你没有var过,又没有赋值不是undefine又能是什么呢??你即使不是eval出来的变量用个普通变量也是一样的啊
eval("z"+y);//没有var就出错了
z1=2
alert(eval("z"+y));
a=ttt.login();
alert(a);
alert(typeof(eval("z"+y)));
因为权限的作用,有时候不输出这个表格到页面,所以有时候id=z1是没定义的,
我就是要判断z1这个表格是否有输出了,所以用z1是否存在来判断,
但是不知怎么判断z1是否存在啊?
但eval是动态命名啊,没有eval就成不了名字好象。
在页面上没有docoment.all.test,当使用eval('document.all.test');时不会显示错误
但是如果使用try...catch...就会得到这个异常
<script language="javascript">
function abc(i){
alert(typeof(eval("document.all.z"+i)));
}
abc(1);
</script>
另外,我查了一下资料,eval()里面的语句如果有返回值,它还会返回这个值
讨论很激烈啊!中午就看到这个贴子了,研究了一小会,但还是弄不出来,后来有事走开了。现在回来一看,倒是学会了如何检测变量是否存在这一招了,感谢楼主和 028city(耶稣爱我)。
这个贴子Mark下来了~!·~
The all collection includes one element object for each valid HTML tag
Returns a reference to the collection of elements contained by the object.
只能判断HTML中的object
可以试一下下面的语句
var test = 'string';
alert(typeof(eval('document.all.test')));
始终都是undifined要判断变量是否存在,还是得靠try...catch()...
function IsValidVariable(Variable){
try{
eval(Variable);
return true;
}
catch(e)
{
return false;
}
}var test;
var VariableName = 'test1';
if ( IsValidVariable(VariableName) == true ){
alert( VariableName + ' is a variable');
}
else
{
alert( VariableName + ' is not a varliable');
}