jquery unbind binding onclick event

background

A set of old code, the page is generated by taglib, and the generated bindings are some operation events, and the whole system is processed in the same way. Now to transform the system, it is necessary to cancel the original operation and replace it with a new event.

accomplish

Write new JS functions directly locally and use

$("#button").unbind("click");
$("#button").bind("click",function(){});

Bind the new js function and unbind the original JS event handler.

The test found that the original function will still be executed. After searching, I found that the original function was implemented in the onclick="test()" method written directly on the DOM. This type of event cannot be unbound only through unbind, and the onclick attribute needs to be removed. Add the following code to test that the original function will no longer be executed.

$("#button").removeAttr('onclick');

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327033820&siteId=291194637