<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">

function test()
{
alert('这是测试方法');
}

function newFun(msg)
{
alert('这是新方法,参数是:'+msg);
}

//实现代码

$("#btnTest").unbind('click').removeAttr('event').click(function() { 

//新方法,如果要替换的新方法已经存在,直接写方法名加参数即可,例如 newFun('测试'); 如果新方法不存在,直接写方法体即可,例如 alert('这是测试方法');

});

//代码分析,1.先通过jQuery的unbind('事件名称,如click')方法解绑click事件,然后removeAttr('onclick'),就能把onclick属性给去掉了 ,最后通过jQuery的bind()或者直接click()来重新绑定我们的click事件

</script>
</head>
<body>
<input id='btnTest' type="button" value="按钮" onclick="test()"/>
</body>
</html>

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2021-09-04
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
猜你喜欢
  • 2022-01-08
  • 2022-12-23
  • 2021-09-27
  • 2021-06-27
  • 2022-02-09
  • 2022-12-23
相关资源
相似解决方案