SoFunction
Updated on 2025-02-28

Solution to incompatibility of JavaScript click event (onclick) in IE8

Blog Garden flash paging is generated using JavaScript. Today, I found that clicking on the page number in IE8 cannot turn the page. The page turn operation is performed in the onclick event of the current page number.

The start code is written like this:

Copy the codeThe code is as follows:

var a = ("a");
("onclick", + "(" + pageIndex + ");(" + pageIndex + ");");

Since IE8 does not support the setAttribute method, the onclick event handler added here has not been added.

Later changed to jQuery's attr method:

Copy the codeThe code is as follows:

$(a).attr("onclick", + "(" + pageIndex + ");(" + pageIndex + ");");

Although this is added, no matter how you click, the onclick event handler will not be executed, and there is no problem with Chrome and Firefox.

Finally, the problem was solved through the following code:

Copy the codeThe code is as follows:

var js = + "(" + pageIndex + ");(" + pageIndex + ");";
= function() { eval(js); }