批量文件上传界面

本文介绍了两种实现批量文件上传的方法。第一种方法通过HTML表单动态添加输入字段实现文件和描述的批量提交;第二种方法则展示了如何使用JavaScript动态创建文件输入框并实时显示已选文件名。

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

方法一:

<html>

<head>
<meta http-equiv="content-type" content="text/html">
<title>locale photo</title>
<script>
function AddMoreRow()
{
    var oRow=event.srcElement.parentNode.parentNode;
    var oTable=oRow.parentNode.parentNode;
    oNewRow=oTable.insertRow();
    for(i=0;i<oRow.cells.length;i++)
    {
        oNewRow.insertCell().innerHTML=oRow.cells[i].innerHTML;
    }
    oRow.all("DelBtn").disabled=false;
    oNewRow.all("DelBtn").disabled=false;
}
function DeleteMoreRow()
{
    var oRow=event.srcElement.parentNode.parentNode;
    var oTable=oRow.parentNode.parentNode;
   if(oTable.rows.length>1)
    {
        oTable.deleteRow(oRow.rowIndex);
        if(oTable.rows.length==1)
        {
           oTable.all("DelBtn").disabled=true;
        }
    }
}
function DisabledKeyInput()
{
    if(event.keyCode!=8&&event.keyCode!=46)
    {
        event.returnValue=false;
    }
}
</script>
</head>

<body topmargin="10">
<form method="post" enctype="multipart/form-data">
<table><th>批量上传</th></table>
<table>

<tr>

<td nowrap="nowrap">名称*</td>
<td><input type="text" name="Name" size="15" maxlength="50"></td>

<td nowrap="nowrap">文件路径*</td>
<td><input type="file" name="FilePath" size="15" onKeyDown="DisabledKeyInput()" /></td>

<td nowrap="nowrap">说明*</td>
<td><input type="text" name="Description" size="45"><input type="button" value="增加"  onclick="AddMoreRow()"></td>

<td nowrap="nowrap"> 
<input type="button" id="DelBtn" value="删除" disabled="disabled" onClick="DeleteMoreRow()">
</td>

</tr>
</table>
<table>
<tr align="center">
<td align="center">
<input type="submit" value="保存">  <input type="reset" value="取消"></td>
</tr>
</table>
</form>
</body>

</html>

 

方法二:

<style>
*{font-size:12px;cursor:default}
.hand{cursor:hand;cursor:pointer}
</style>
<body>
<form name=fm1>
<div id=bxAttList>
    <div id=bxAtt onmouseover="$('bxAtt1').style.textDecoration='underline'" onmouseout="$('bxAtt1').style.textDecoration=''" style=float:left;width:60>
        <span id=bxAtt1 style='position:absolute;padding-top:3;cursor:hand;font-family:宋体'>@添加附件</span>
        <span id=bxAtt2 onmouseover=this.scrollLeft=100 style=position:absolute;width:60;overflow:hidden;filter:alpha(opacity=0);-moz-opacity:0></span>
    </div>
</div>
</form>
</body>
<script>
file_create()
function file_create(){
    $("bxAtt2").innerHTML="<input onchange=file_change(this) hidefocus type=file name=file1 size=1 class=hand>"
}
function file_change(tx){
    var sName,o
    sName=tx.value.replace(////g,"/").replace(/(.*//)(.*)/,"$2")
    o=document.createElement("nobr")
    o.style.cssText="float:left;margin-right:6;padding-top:3;color:darkgreen"
    o.innerHTML="□"+sName+"<font onclick=$('bxAttList').removeChild(this.parentNode);file_repos() class=hand style=color:red;font-weight:bold>"+unescape("×")+"</font>"
    tx.style.display="none"
    o.appendChild(tx)
    $("bxAttList").insertBefore(o,$("bxAtt"))
    file_repos()
    file_create()
}
function file_repos(){
    $("bxAttList").appendChild($("bxAtt"))
}
function $(obj){
    return typeof(obj)=="object"?obj:document.getElementById(obj)
}
</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值