Home  >  Article  >  Web Front-end  >  Use jQuery's attr method to modify the onclick value_jquery

Use jQuery's attr method to modify the onclick value_jquery

WBOY
WBOYOriginal
2016-05-16 16:42:191629browse

Okay, let’s just paste the js code for everyone

var js = "alert('B:' + this.id); return false;"; 
var newclick = eval("(function(){"+js+"});"); 
$("#anchor").attr('onclick', '').click(newclick);

If the onclick event originally had a value, it must be cleared first and then assigned using click( eval(function(){.....}) )

$("input[name='orderCar']").attr('onclick','').click( eval(function(){Test()})); 

function Test(){ 
alert("测试通过!"); 
return; 
}

If I can help you, please step on me hard down there.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn