晨风

-------------------- 业精于勤,荒于嬉;行成于思,毁于随

导航

通过jQuery的attr修改onclick(转)

Posted on 2013-01-24 15:20  shenyixin  阅读(1030)  评论(0编辑  收藏  举报
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