我有一个像这样的代码:
<html>
<head>
<script language="javascript">
window.onload = function() {
for(i = 0; i < 26; i++) {
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
x.setAttribute("value", String.fromCharCode(i + 65));
x.setAttribute("id", String.fromCharCode(i + 65));
x.setAttribute("onclick", "isTOF(self.id)");
document.body.appendChild(x);
}
}
function isTOF(v) {
alert(v);
}
</script>
</head>
<body>
</body>
</html>
例如,当我点击"A"按钮时,程序应该弹出'A'。
但它弹出了“undefined”。
我不知道问题出在哪里。
我想让我的代码正常工作。
我该怎么做?
self.id
是什么? - tkauslself
不存在。 - tkauslself
不存在? - Hoseong Jeonthis.id
可以工作... - moilejter