Now after clicking the button, remove the onclick event and bind a new click event to the button. On the second click, the second event processing function starts to be executed. The code of the second processing function: reclick code:
function btnOKClick() { alert("btnOK Clicked"); $('#btnOK').attr('onclick' , '').bind('click', function () { reclick(); }); }
This method works normally under Google Chrome, but is not compatible with IE The reclick method will be called immediately in mode, which is not the effect we want.
The reason for this effect seems to be that after onclick is executed, IE goes back to check whether there is a handler bound to click. The structure is there, so it is executed immediately.
In order to solve this problem, we can change the idea and delay binding the click event. The specific code is as follows:
function btnOKClick() { alert("btnOK Clicked"); setTimeout(function () { $('#btnOK').attr('onclick', '').bind('click', function () { reclick (); }); }, 1); }
The setTimeout timer is used here. After the timer is triggered, the onclick attribute is removed and click is bound. handler code. After testing, it can run normally in both the compatibility mode and non-compatibility mode of IE9; Google Chrome also runs normally.
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn