input type file in Opera
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;
开发者_如何学C 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>
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.
精彩评论