代码如下:

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);

来源:changing the value of onclick with or without jQuery

相关文章: