Use jQuery's attr method to modify the onclick value

  • 2020-03-30 03:29:45
  • OfStack

Okay, so I'm just going to stick you with the js code

var js = "alert('B:' +; return false;"; 
var newclick = eval("(function(){"+js+"});"); 
$("#anchor").attr('onclick', '').click(newclick);

If the onclick event has a value, clear it, and then use the click(eval(function(){... })) assignment

$("input[name='orderCar']").attr('onclick','').click( eval(function(){Test()})); 

function Test(){ 
alert(" Test passed! "); 

  If it can help you, please step on it.

Related articles: