<input type="button" onclick="test()" />
<form id="f"></form>
<script type="text/javascript">
function test() {
var t = document.createElement('<input id="1" type="button" onclick="showid(this.id)" \/>');
f.insertBefore(t);
} function showid(id) {
alert(id);
}
</script>
IE ONLY其实还可以这样写.LZ的问题...
t.onclick="showid(this.id)"
改成
t.onclick=function () { showid(this.id) };
或者
t.onclick= new Function("showid(this.id)");
都可以
<form id="f"></form>
<script type="text/javascript">
function test() {
var t = document.createElement('<input id="1" type="button" onclick="showid(this.id)" \/>');
f.insertBefore(t);
} function showid(id) {
alert(id);
}
</script>
IE ONLY其实还可以这样写.LZ的问题...
t.onclick="showid(this.id)"
改成
t.onclick=function () { showid(this.id) };
或者
t.onclick= new Function("showid(this.id)");
都可以
var t=document.createElement(" <input>");
改成
var t=document.createElement("input");