IE 9 jQuery没有设置输入值 [英] IE 9 jQuery not setting input value

查看:110
本文介绍了IE 9 jQuery没有设置输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:

我有一个输入文件字段,我想限制它只通过Jquery接受.GIFs,如果格式错误,设置输入值为空。



问题是在IE9上, .val('')不行。任何想法?

我的jQuery:

$ $ p $ $ $('input [ ()函数(){
var val = $(this).val();
switch(val.substring(val.lastIndexOf('。')+ 1) .toLowerCase()){
case'gif':
break;
default:
//错误信息
alert(Wrong Format);
$(this).val('');
break;
}
});


解决方案

从IE8开始,只读:

 <$ c $ 。C> $( 输入[类型= '文件'])replaceWith($( 输入[类型= '文件'])的克隆(真)); 

从这里选择: SO Anwser


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;
    }
});​

解决方案

From IE8 it is readonly try:

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

Picked from here : SO Anwser

这篇关于IE 9 jQuery没有设置输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆