通过jQuery的attr修改onclick

代码如下:

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

原文地址:https://www.cnblogs.com/dudu/p/1674690.html