IE requires double click with custom button

前端 未结 6 1166
刺人心
刺人心 2021-02-07 13:50

I have a script that is dived as:

HTML:

Cl
6条回答
  •  不思量自难忘°
    2021-02-07 14:18

    I found another more simple solution, just trigger the event "click" on mousedown for this element only:

    $("input").mousedown(function() {
        $(this).trigger('click');
    })
    

    in order to avoid problems on other browsers, apply this solution to IE only:

    if ($.browser.msie && parseInt($.browser.version, 10) > 8) {
        $("#your_file_input").mousedown(function(event) {
            if (event.which == 1) {
                $(this).trigger('click');
            }
        })
    }
    

    here's your jfiddle modified, check it on IE 9-10: http://jsfiddle.net/7Lq3k/

    Edit: example modified in order to limit the event handling for left click only (see: How to distinguish between left and right mouse click with jQuery for details)

提交回复
热议问题