怎么让input type="file" 不可编辑

 

今天在做项目的时候,遇到上传文本框的问题,
<input type="file" size="100" name="photoupload" />
在firefox中,该控件产生的文本框是默认不可编辑的,但是在IE下,该文本框可编辑,
根据用户需要,此文本框应为不可编辑。
但是直接将其设置为“readonly”或者“disabled”后,对应的浏览按钮也无法使用了。所以此法不通。

在网上搜索了一些资料,主要有以下几种方法:
1.变通处理:
<input type=file id=a1 style="visibility:hidden">
<input id=a2 type=text readonly>
<input type=button value=浏览 οnclick="a1.click(); a2.value= a1.value">
2.增加如下属性:
contenteditable="false"

实例代码:

<input type="file" style="width: 446px" id="ptlFile" contenteditable="false"/>

对比一下,第二种简单方便,问题解决。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
for (var i = 0; i < cellsCount; i++) { var newCell = newRow.insertCell(); newCell.contentEditable = true; var previousCell = previousRow.cells[i]; // 获取上一行对应列的单元格 var previousInput = previousCell.querySelector('input[type="text"]'); if (previousInput) { var newTextArea = document.createElement("textarea"); newTextArea.name = previousInput.name; newCell.appendChild(newTextArea); } else if (previousCell.querySelector('input[type="file"]')) { var newImageInput = document.createElement("input"); newImageInput.type = "file"; newImageInput.name = previousCell.querySelector('input[type="file"]').name; // 继承上一行对应列的文件输入框属性 newImageInput.onchange = function () { previewImage(this); }; newImageInput.onclick = function () { showPopup(this.src); }; newCell.appendChild(newImageInput); } else { var newTextArea = document.createElement("textarea"); newTextArea.name = "yourTextareaName"; // 替换为你的文本框名称 newCell.appendChild(newTextArea); }这是我新增按钮按钮的代码,<td class="auto-wrap"><textarea name="aoi_step">3</textarea></td> <td class="auto-wrap"><textarea name="defect_type">Particle</textarea></td> <td class="auto-wrap"><textarea name="layer_code">ACT</textarea></td> <td class="auto-wrap"><textarea name="type">Particle</textarea></td> <td class="auto-wrap"><textarea name="dpet">ACT</textarea></td> <td class="auto-wrap"><textarea name="subcode">Particle</textarea></td> <td class="auto-wrap"><textarea name="code_description">ACT</textarea></td> <td><input type="file" name="image1_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"></td> <td> <input type="file" name="image2_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td> <input type="file" name="image3_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td> <input type="file" name="image4_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td> <input type="file" name="image5_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td class="auto-wrap"><input type="text" name="determination_rule" value="ACT"></td> 这是我的表格,在我新增单元格时,是要将对应列的类名添加到新增的单元格,并使文本框不可拖动改变大小
最新发布
07-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值