input type file in Opera

你。 提交于 2019-12-11 08:06:16

问题


I have tried to fire onkeydown, onkeypress and onkeyup events on file input(e.g. when the element is on focus and a key is pressed the events are not fired), but they doesn't work in Opera. Firing 'click' with jQuery , doesn't work too (e.g. $('#myFileinput').Click() or $('#myFileinput').trigger('click')).

Is there a way to trigger these events in Opera ?

Here is my code:

 <input type="file" class="foo" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript">
    debugger;
    window.onload = onPageLoad;
    function onPageLoad() {

        var input = $(".foo");
        debugger;
        input.keydown(function () {
            //doesn't work in Opera
            alert("keydown");
        });

        input.keypress(function () {
            //doesn't work in Opera
            alert("keypress");
        });

        input.keyup(function () {
            //doesn't work in Opera 
            alert("keyup");
        })
    }

    window.onkeydown = function () {
        //when the focus is on the input the code bellow doesn't fire
        alert("window key down")

    }

</script>

回答1:


Due to security policies, it is limited what events Opera fires on an input type=file. Also, in new Opera versions focusing the input will bring up a file dialog, so no key events would ever fire on the input anyway. If you need to know when the value changes, listen for the change event.



来源:https://stackoverflow.com/questions/5936909/input-type-file-in-opera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!