javascript - IE8下jquery无法设置textarea的值
本文介绍了javascript - IE8下jquery无法设置textarea的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
点击选择文件,选择好文件后,后面的未选择文件变成选择文件的文件名,但是IE8无效,求解。。
以下是代码
<div class="fl psr"><a href="javascript:;" class="sui-btn" style=" border-color:#666666;">选择文件</a><input type="file" name="file" id="file" value=""><br/><a href="" style="color:#1d4fe2;" class="ml10 lh20">下载模版</a></div>
<textarea id="aim" readonly>未选择......文件</textarea>
var file = $('#file'),
aim = $('#aim');
file.on('change', function( e ){
var name = e.currentTarget.files[0].name;
aim.val( name );
});
jquery是jquery-1.8.3.min.js这个版本,不能使用更低版本的,项目要求最低兼容ie8,真的难受
解决方案
这样IE应该兼容
<script>
document.getElementById("file").onchange=function(){
document.getElementById("aim").value= this.value;
}
</script>
这篇关于javascript - IE8下jquery无法设置textarea的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文