上传表格input【type="file"】

本文介绍了一个用于验证并上传Excel文件(支持2003及2007版本)的JavaScript脚本实现。该脚本包括文件格式验证、提交前检查以及通过AJAX请求判断后台是否处于数据导入锁定状态的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript">
//验证上传的格式
 function clickFileName(upload_field) {
var filename = upload_field.value;
var newFileName = filename.split('.');     
newFileName = newFileName[newFileName.length-1];
if (/^(xls|xlsx|XLS|XLSX)$/.test(newFileName)==false) {                 
alert("上传的文件格式只能为Excel格式(2003或者2007版本的)");
    upload_field.form.reset();
    return false;
}
}
//提交前验证提交的数据
 function verityFile(){
     if($("#userfile").val()==null||$("#userfile").val()==''||$("#userfile").val()=="undefined"){
alert("请选择文件导入!");
return false;
}
     var lockFlag = isLock();
     if (lockFlag){
    alert('已有数据正在导入,请稍后再试!');
    return false;
     }
return true;
 }
 //判断是否有数据正在导入
 function isLock(){
var isLock = false;
$.ajax({
         type:"post",
         async:false,
         url:"<%=basePath%>propertyPayment_Payment_importPropertyInfoLock.do",
         success:function(data,status){
             if(status && data == '0'){
            isLock = true;
             }
         }
     });
return isLock;
 }
 

</script>

        <table width="610px" border="0" cellpadding="1" cellspacing="0">
  <tr>
  <td width="100%">
  <form id="uploadForm" name="uploadForm" method="post" enctype="multipart/form-data" action="***_Payment_importPropertyInfo.do" onsubmit="return verityFile()">
  <table id="personal_table" border="0" cellpadding="2" cellspacing="1" width="100%" align="center" style="">
                            
    <tr style=" COLOR: #000;" >
    <td width="10%">文件上传:</td>
                                <td width="63%">
                                   <input type="file" id="userfile" name="userfile" onchange="clickFileName(this)" >
                                </td>
    </tr> 
                            
                            <tr >
    <td nowrap="nowrap" ></td>
    <td > 
                                   <input class="input_img"  type="submit"   value="提交"/>
                                </td>
    </tr>
  </table>


</form>
  </td>
  </tr>
</table>


<tr> <th contenteditable="true" ><input type="text" oninput="filterTable(1)" placeholder="aoiStep" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(2)" placeholder="defectType" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(3)" placeholder="layerCode" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(4)" placeholder="type"></th> <th contenteditable="true" ><input type="text" oninput="filterTable(5)" placeholder="dpet" ></th> <th contenteditable="true"><input type="text" oninput="filterTable(6)" placeholder="subcode" ></th> <th contenteditable="true" ><input type="text" placeholder="codeDescription" ></th> <th contenteditable="true" >image1</th> <th contenteditable="true" >image2</th> <th contenteditable="true">image3</th> <th contenteditable="true" >image4</th> <th contenteditable="true" >image5</th> <th contenteditable="true" ><input type="text" placeholder="determination_rule"></th> </tr> </thead> <tbody> <form action="upload.php" method="POST" enctype="multipart/form-data"> <tr> <td input type="text" name="aoi_step">3</td> <td input type="text" name="defect_type">Particle</td> <td input type="text" name="layer_code">ACT</td> <td input type="text" name="type">Particle</td> <td input type="text" name="dpet">ACT</td> <td input type="text" name="subcode">Particle</td> <td input type="text" name="code_description">ACT</td> <td> <input type="file" name="image1_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> <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 input type="text" name="determination_rule">Particle</td> <table id="data_table"> <thead> </form> </tbody> </table> 我只需要上传表格内容,不需要上传表头内容,应该怎么处理
07-23
<div class="table-container"> <table id="myTable"> <thead> <tr> <th contenteditable="true" ><input type="text" oninput="filterTable(1)" placeholder="aoiStep" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(2)" placeholder="defectType" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(3)" placeholder="layerCode" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(4)" placeholder="type"></th> <th contenteditable="true" ><input type="text" oninput="filterTable(5)" placeholder="dpet" ></th> <th contenteditable="true"><input type="text" oninput="filterTable(6)" placeholder="subcode" ></th> <th contenteditable="true" ><input type="text" placeholder="codeDescription" ></th> <th contenteditable="true" >image1</th> <th contenteditable="true" >image2</th> <th contenteditable="true">image3</th> <th contenteditable="true" >image4</th> <th contenteditable="true" >image5</th> <th contenteditable="true" ><input type="text" placeholder="determination_rule"></th> </tr> </thead> <tbody> <form action="unload.php" method="POST" enctype="multipart/form-data"> <tr> <td input type="text" name="aoi_step">3</td> <td input type="text" name="defect_type">Particle</td> <td input type="text" name="layer_code">ACT</td> <td input type="text" name="type">Particle</td> <td input type="text" name="dpet">ACT</td> <td input type="text" name="subcode">Particle</td> <td input type="text" name="code_description">ACT</td> <td> <input type="file" name="image1_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> <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 input type="text" name="determination_rule">Particle</td> <tr> <button type="submit">提交</button> </tr> </form> </tbody> </div> <script>修改后在我提娜佳图片是报错
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值