我在创建新的节点时,使用newElement.attachEvent("onchange",cktype(this))方法绑定了cktype(obj)函数,但是节点还每创建,cktype()函数就已经被执行了,返回了一个undefined值。
换了一个方法:
再执行完newdiv.appendChild(newElement);之后,在执行document.getElementById(i).onchange="cktype(this)";绑定cktype()函数。但是,这样的话,连cktype()都不会被执行~~
大家帮帮忙吧~~
换了一个方法:
再执行完newdiv.appendChild(newElement);之后,在执行document.getElementById(i).onchange="cktype(this)";绑定cktype()函数。但是,这样的话,连cktype()都不会被执行~~
大家帮帮忙吧~~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
</head>
<body>
<select id="sItems">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
<script type="text/javascript">
document.getElementById("sItems").onchange = function(){
var obj = event.srcElement;
alert(obj.value);
}
</script>
</body>
</html>
document.getElementById(i).onchange=cktype;
这样即可调用,括号省略