代码如下:

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2021-08-10
  • 2022-12-23
  • 2022-02-04
  • 2021-11-08
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
相关资源
相似解决方案