jQuery, $(element).click doesn't work on ie<

2019-07-15 01:00发布

I have a click event with jQuery like that :

$(document).ready(function() {    
    $("#id_secteur_activite").click(function () {    
        console.log('ok');    
    });
});

On firefox and ie9, when i click on my element #id_secteur_activite, i have the message "ok" in my console.

But when i test on ie 8 and ie7, i have nothing. .click doesn't work on ie<9.

Do you have any ideas ? thanks !

Edit :

<SELECT id=id_secteur_activite name=secteur_activite>
<OPTION selected value="">choisissez d'abord un secteur d'activité</OPTION>
</SELECT>

3条回答
孤傲高冷的网名
2楼-- · 2019-07-15 01:26

[DEMO(http://jsfiddle.net/mplungjan/8t8Jh/show/)

All works using a high enough version of jQuery (here edge which is currently v1.9.2pre)

$(document).ready(function() {    
/*    $("#id_secteur_activite").click(function () {    
        console.log('click');    
    });
*/    
    $("#id_secteur_activite").on("click",function () {    
        console.log('click');    
    });
    $("#id_secteur_activite").on("change",function () {    
        console.log('change');    
    });
});
查看更多
可以哭但决不认输i
3楼-- · 2019-07-15 01:31

use .on()

$(document).ready(function() {    
    $("#id_secteur_activite").on('click',function () {
        alert('ok');    
    });
});

and also use alert instead of console.

查看更多
不美不萌又怎样
4楼-- · 2019-07-15 01:36

you can use both click event and change event.

$(document).ready(function() {    
    $("#id_secteur_activite").on('change',function () {    
        console.log('ok');    
    });
});
查看更多
登录 后发表回答