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);
转自:http://www.cnblogs.com/dudu/archive/2010/02/27/1674690.html