【问题标题】:Change event for input type file not working输入类型文件的更改事件不起作用
【发布时间】:2011-10-19 20:16:24
【问题描述】:

您好,我需要获取用户从输入类型文件控件中选择的文件的名称并将其显示在页面上。 jquery onchange 事件在 ie 8 中不起作用。谁能告诉我解决方案?

//这是我的jquery代码

$(document).ready(function() 
{
    $('input[type=file]').change(function(){
        var val=$('input[type=file]').val();    
        alert(val);
        $("#textfile").attr("value", val);
        });
}); 

//HTML代码

<input type="file" class="file" name="upload_file" id="UserIcon" /> 
<input type="text" id='textfile' width="100px" />

但在 IE 上传后我看到文件后添加了一些东西

input name="upload_file" class="file" id="UserIcon" type="file" jQuery15102237614897631498="27" value="C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg"/>

【问题讨论】:

  • 尝试使用 [type="file"]。此外,您可以在处理函数中使用 $(this) 获取值 - var val = $(this).val();

标签: jquery html forms jquery-selectors


【解决方案1】:

这不是 jQuery 问题,而是 JavaScript 问题。据我所知,IE 不知道 onchange 事件处理程序。尝试点击而不是更改。

Getting jQuery to recognise .change() in IE

【讨论】:

    猜你喜欢
    • 2019-11-11
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    相关资源
    最近更新 更多