日期:2014-05-16 浏览次数:20432 次
var btn; function a() { btn = document.createElement("button"); btn.setAttribute("onclick", "b();"); btn.innerHTML = "A"; document.body.appendChild(btn); } function b() { btn.innerHTML = "B"; }
<button onclick="a();">创建和修改</button>
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <button onclick="a();">创建和修改</button> <script> var btn; function a() { btn = document.createElement("button"); btn.onclick = function(){ b(this) } btn.innerHTML = "A"; document.body.appendChild(btn); } function b(btn) { btn.innerHTML = "B"; } </script> </body> </html>
------解决方案--------------------
<html>
<head>
<meta charset="gb2312" />
<title></title>
</head>
<body>
<button onclick="a();">创建和修改</button>
<script>
var btn;
function a() {
btn = document.createElement("button");
btn.onclick = b
btn.innerHTML = "A";
document.body.appendChild(btn);
}
function b() {
this.innerHTML = "B";
}
</script>
</body>
</html>
这样试试