日期:2014-05-18  浏览次数:20720 次

如何用javascript改button的onclick=""里面的值
小弟有一个项目,要想实现这个功能:

就是用JAVASCRIPT   改变button里的onclick属性中的内容,请帮小弟写一个~

------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
<input type= "button " name= "test " id= "test ">
</BODY>
</HTML>
<script language= "javascript ">
var obj = document.getElementById( "test ");
if (window.attachEvent)
{
obj.attachEvent( "onclick ", function(){alert( "only IE can use me ");});
}
else
{
obj.addEventListener( "click ", function(){alert( "except IE use me ");}, false);
}
</script>