Home >Web Front-end >JS Tutorial >Use jQuery's attr method to modify the onclick value_jquery
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.