Home > Web Front-end > JS Tutorial > Solution to the incompatibility of IE8's JavaScript click event (onclick)_javascript skills

Solution to the incompatibility of IE8's JavaScript click event (onclick)_javascript skills

WBOY
Release: 2016-05-16 17:13:03
Original
2189 people have browsed it

The blog park flash paging is generated using JavaScript. Today I found that clicking on the page number cannot turn the page under IE8. The page turning operation is performed in the onclick event of the current page number.

The starting code is written like this:

Copy the codeThe code is as follows:

var a = document.createElement("a");
a.setAttribute("onclick", this.ClickFunctionName "(" pageIndex ");Pager.SetCurrent(" 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 code The code is as follows:

$ (a).attr("onclick", this.ClickFunctionName "(" pageIndex ");Pager.SetCurrent(" pageIndex ");");

Although it has been added, no matter how you click, the onclick event handler does not execute. Chrome and Firefox do not have this problem.

The problem was finally solved by the following code:

Copy the code The code is as follows:

var js = this.ClickFunctionName "(" pageIndex ");Pager.SetCurrent(" pageIndex ");";
a.onclick = function() { eval(js); }
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template