简体   繁体   English

更改href或删除按钮的onclick

[英]changing the href or removing the onclick for a button

<a href="javascript:__doPostBack('btnContinuePhone','')" class="button-hpo blue-button-23" id="btnContinuePhone" onclick="javascript:return ConfirmModalPopUp('phone');"><span>Next</span></a>

I want to change the href of this button and also removing on click. 我想更改此按钮的href,也要单击删除。 Could anybody tells me how to do it in jquery? 有人可以告诉我如何在jquery中做到吗?

You can try something like this: 您可以尝试如下操作:

var el = $("#element");
if (el){
    el.unbind("click");
    el.attr("href", "newpage.htm");
}

Here is a demo attached: http://jsfiddle.net/xavi3r/DQ4Sn/ 这是附带的演示: http : //jsfiddle.net/xavi3r/DQ4Sn/

$('#btnContinuePhone').click(function(){
   return false; 
});
$('#btnContinuePhone').attr('href','http://newurl.com');

This is my solution : 这是我的解决方案:

$('#btnContinuePhone').attr('href', 'what ever you like');
$('#btnContinuePhone').click(function(){ return false;});

Or you can do that alternativly: 或者您可以交替进行:

$('#btnContinuePhone').attr('href', 'what ever you like');
$('#btnContinuePhone').click(function(e){ e.preventDefault(); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM