IE 9 jQuery not setting input value

2019-02-20 08:11发布

my question is simple:

I have an input file field, and i want to limit it to only accept .GIFs via Jquery , and if the format is wrong, set the input value blank.

The problem is that on IE9, the .val('') does not work. Any ideas?

My jQuery:

$('input[type=file]').change(function() {
    var val = $(this).val();
    switch (val.substring(val.lastIndexOf('.') + 1).toLowerCase()) {
    case 'gif':
        break;
    default:
        // error message here
        alert("Wrong Format");
        $(this).val('');
        break;
    }
});​

1条回答
萌系小妹纸
2楼-- · 2019-02-20 08:43

From IE8 it is readonly try:

$("input[type='file']").replaceWith($("input[type='file']").clone(true));

Picked from here : SO Anwser

查看更多
登录 后发表回答