21,887
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script language="javascript">
attachNum=0;
function add(){
attachNum=attachNum+1;
var html="<input name='attachName[]' type='file'> <input type='button' value='删除' onclick=\"remove("+attachNum+")\">";
var divAttach=document.getElementById('divAttach');
var div=document.createElement('div');
div.setAttribute('id','attachNum'+attachNum);
div.innerHTML=html;
divAttach.appendChild(div);
div.childNodes[0].click();
}
function remove(attachNum){
document.getElementById('divAttach').removeChild(document.getElementById('attachNum'+attachNum));
}
function fileSubmit(){
document.getElementsByName('form1')[0].submit();
}
</script>
</head>
<body>
<form enctype="multipart/form-data" method="POST" name="form1" action="b.php">
<table align="center" class="small" cellpadding="2" cellspacing="1" align="center" width="90%" >
<tr>
<td>
<input type=button onClick="add();" value="添加附件" />
<div id="divAttach"></div>
</td>
</tr>
<tr>
<td>
<input type="button" value="立即发送" onclick="fileSubmit();"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
var_dump($_FILES["attachName"]["name"]);
?>