您现在的位置是:首页 > 电脑技术查询 > web开发

如何解决文件选择框只能选择文件不能自己输入文件地址

编辑:chaxungu时间:2022-10-02 23:23:26分类:web开发

怎么解决文件选择框只能选择文件不能自己输入文件地址?
就是 <input type = file onkeypress= "return false ">
我加了一个onkeypress= "return false "。这样用户就不能从键盘输入文字了,但是用户可以把文字粘贴进来,或者选择完文件以后用backspace删除一些文字,怎么禁止这些操作呢???

------解决方案--------------------
<script>
function doClick(obj){
obj.readOnly=false;
setTimeout( 'document.getElementById( "aaa ").readOnly = true ',1);
}
</script>


<input type = file id=aaa readonly onclick= "doClick(this) ">