1、使用setAttribute()改變網(wǎng)頁(yè)中標(biāo)簽的onclick屬性
2、IE中通過(guò) setAttribute添加的屬性
1、使用setAttribute()改變網(wǎng)頁(yè)中標(biāo)簽的onclick屬性 *p1
setAttribute設(shè)置style和onclick這些屬性在IE中是行不通的。
<script type="text/javascript">
function cancleEvent()
{
document.getElementById('a').setAttribute("onclick",'');
document.getElementById('g').innerHTML="取消事件!";
}
function setEvent()
{
document.getElementById('a').setAttribute("onclick",'alert("你好!")');//firefox
document.getElementById('a').onclick= function () { alert("This is a test!"); }//IE firefox也有作用,但是使用firebug調(diào)試看不到修改后的效果,使用上面的方法可以看到。
document.getElementById('Div1').innerHTML="設(shè)置事件!";
}
</script>
注:
*p1:使用setAttribute()改變網(wǎng)頁(yè)中標(biāo)簽的onclick屬性
http://blog.csdn.net/Cnami/archive/2008/05/27/2486516.aspx
2、IE中通過(guò) setAttribute添加的屬性 *p2
IE下setAttribute設(shè)置元素的對(duì)象、集合和事件屬性都只當(dāng)成普通屬性,起不到原有的作用,但可以直接進(jìn)行賦值操作。
<script language="javascript" type="text/javascript">
<!--
function init() {
var obj = document.getElementById("btn");
obj.onclick=changeValue;
obj.style.background="#CC6600";
}
function changeValue() {
document.getElementById("txt").value = "New value!";
}
-->
</script>
注:
*p2:[求助]通過(guò) setAttribute 添加的屬性在 IE 下不被實(shí)現(xiàn)?
http://bbs.blueidea.com/viewthread.php?tid=2290521
posted on 2010-05-11 00:10
黃小二 閱讀(403)
評(píng)論(0) 編輯 收藏 所屬分類:
Ajax