简体   繁体   中英

jquery ON event not firing in IE8

I made this jsfiddle to demonstrate what I am meaning, but unfortunately JSfiddle itself doesn't seem to work with IE8 so you need to test this jsfiddle code in a stand alone page: http://jsfiddle.net/4Bdbn/

With IE8 the above ON events does not fire, absolutely nothing happens. even adding an alert("hi") to the function does nothing; it doesn't get called, plus no errors are reporting in the console.

On a side note, is e.preventDefault() necessary to prevent a function being executed multiple times when you have multiple events triggering the same function, such as .on("touchstart click",.... ? In all situations?

jQuery version 1.8.3 so I believe IE8 is a supported browser.

ps. Im using IE10 in Browser Mode IE8.

EDIT: My simple test page which is not working in IE8 (for me): http://www.personaltrainer.com.au/test.php

The relevant code section is...

<script type="application/javascript">
$(document).ready(function () {
    $("body").on("click touchstart",".something",function(e) {
        $(this).text($(this).text() + " "+e.type);
        e.preventDefault();
    });
});
</script>

Thanks!

You're using an invalid type attribute ( application/javascript ) on your script tag. Change it to text/javascript or simply remove it all together.

This works just fine in IE8 (real version)

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script>
$(document).ready(function () {
    $("body").on("click touchstart",".something",function(e) {
        $(this).text($(this).text() + " "+e.type);
    });
});
</script>

maybe you should remove the touchstart event first to check if it works! IE8 actually dosn't support touch action!

$(function () {
    $("body").on("click",".something", function(e) {
        $(this).text($(this).text() + " " + e.type);    
        //e.preventDefault();   
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM