【发布时间】: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