<input type="button" id="b" onclick="click1();" value="确定"><br><br>
<a href="javascript:;" onclick="change_click();">点击修改button的click事件</a>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function change_click()
{
$("#b").unbind('click');
$("#b").bind({
click: click2()
});
}
function click1()
{
alert(1);
}
function click2()
{
alert(2);
}
</script>
这样我点击链接是就会触发按钮的click事件,我希望实现点击链接时修改按钮的click时间,当再点击确定时触发的是click2函数,该怎么实现?
------解决方案--------------------
- PHP code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <input type="button" id="b" value="确定"><br><br> <a href="javascript:;" onclick="change_click();return false;">点击修改button的click事件</a> <script src="js/jquery.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $("#b").bind('click',click1); }); function change_click() { $("#b").unbind('click'); $("#b").bind("click", click2); } function click1() { alert(1); } function click2() { alert(2); } </script>