读书人

新增加一个DIV加入方法onclick 可以

发布时间: 2012-04-09 13:41:25 作者: rapoo

新增加一个DIV,,加入方法onclick 可以/onMouseOver不可以?
<input type= "button " name= "aa " value= "aa " onclick= "showDiv(); "/>
ABCDE

<script>
function t1(){
alert( "tt ");
}

function showDiv(){
var div = document.createElement( "div ");
div.id = "div1 ";
div.style.top = 300;
div.style.left = 300;
div.style.backgroundColor = "red ";
div.style.display = "inline ";

div.setAttribute( "onMouseOver ", document.all ? eval(function(){t1()}) : 'javascript:t1() ');
div.setAttribute( "onclick ", document.all ? eval(function(){t1()}) : 'javascript:t1() ');

div.innerHTML = "hello, world. ";
document.body.appendChild(div);
}
</script>

---------------
以上代码 onclick 可以/onMouseOver不可以

为什么啊?

[解决办法]
<input type= "button " name= "aa " value= "aa " onmouseover= "showDiv(); "/>

可以,注意大小写

读书人网 >JavaScript

热点推荐