html代码
JQuery代码
function change(id,status1,status2){ let btns = $("#btn-"+id+" a"); ........ btns.each(function(index,element){ $(this).removeAttr('onclick').attr("onclick","change("+id+",2,"+index+")"); //JQuery动态修改onclick函数的参数值 }); }
在JQuery中通过attr方法为元素添加函数,网上的资料一般都是这么介绍的,但是如果元素本身已经有同名函数了,那么要先通过removeAttr方法移除同名函数后再通过attr方法添加,也就达到了动态修改函数参数值的目的了。

博悦天下







