Home > Web Front-end > JS Tutorial > body text

Solution to the problem of invalidity caused by dynamically changing the onclick attribute in jquery_jquery

WBOY
Release: 2016-05-16 17:10:43
Original
1191 people have browsed it
Copy code The code is as follows:

  • < /li>

  • Although writing this way is not recommended in many cases, there are still times when you will encounter such code.

    Then you may need to modify the onclick attribute at some point as follows:
    Copy the code The code is as follows:

    $("#id").attr("onclick",url);

    Code like this can get what you want in chrome and firefox result.

    Unfortunately, in IE, at least IE7 and below have no effect. As for i8, it seems to have no effect.

    The way is to use jquery binding.
    Copy the code The code is as follows:

    $("#id").attr("onclick","").click(function(){
    //
    });

    You need to clear onclick here first The value of the attribute is displayed after binding.

    If the onclick attribute has not been set, there is no need to clear it.
    Copy the code The code is as follows:

    $("#id").click(funciton(){
    //
    });
    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
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!