Home  >  Article  >  Web Front-end  >  使用jQuery的attr方法来修改onclick值_jquery

使用jQuery的attr方法来修改onclick值_jquery

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

好了,直接给大家贴上js代码吧

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

如果onclick事件原先有值,要先清空,再用click( eval(function(){.....}) )赋值

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

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

 如果能帮到你,麻烦你在下面狠狠踩上一脚。

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