原文地址:http://www.oschina.net/code/snippet_111193_15135
var js = "alert('B:' + this.id); return false;";
// creates a function from the "js" string
var newclick = eval("(function(){"+js+"});");
// clears onclick then sets click
$("#anchor").attr('onclick', '').click(newclick);
如果onclick事件原先有值,要先清空,再用click( eval(
function
(){.....}) )赋值:
$("input[name='orderCar']").attr('onclick','').click( eval(function(){warningT()}));
function warningT(){
alert("看到了吧!");
return;
}