代码如下:
function aa(){
document.fileForm.t1.click();
var val=document.fileForm.t1.value;
if(val==""){
return;
}else{
var tt=document.fileForm.sele;
var tiem=document.createElement("OPTION");
tt.options.add(tiem);
tiem.value=val;
tiem.innerText=val;
document.fileForm.t1.value=""
var v=document.fileForm.t1.value;
}
} <input id="t1" type="file" style="display:none"> <p>
<select style="FONT-SIZE: 12px; WIDTH: 90%; COLOR: #006cad; BACKGROUND-COLOR: #ffffff" multiple="multiple" size="12" name="sele" id="sele">
</select>
<input type=button value="上传文件" style="font-size:12px;height:19"onclick="blur();aa()"/>请问我能不能把file中的内容写到select中后,把file输入框的内容置为空?
function aa(){
document.fileForm.t1.click();
var val=document.fileForm.t1.value;
if(val==""){
return;
}else{
var tt=document.fileForm.sele;
var tiem=document.createElement("OPTION");
tt.options.add(tiem);
tiem.value=val;
tiem.innerText=val;
document.fileForm.t1.value=""
var v=document.fileForm.t1.value;
}
} <input id="t1" type="file" style="display:none"> <p>
<select style="FONT-SIZE: 12px; WIDTH: 90%; COLOR: #006cad; BACKGROUND-COLOR: #ffffff" multiple="multiple" size="12" name="sele" id="sele">
</select>
<input type=button value="上传文件" style="font-size:12px;height:19"onclick="blur();aa()"/>请问我能不能把file中的内容写到select中后,把file输入框的内容置为空?
input id="t1" type="file"
添加js事件,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function $(sId){
return document.getElementById(sId);
}function fileSel(e){
var oBody=document.body;
var evt=e||event;
var oSel=$("sel1");
var oFile=evt.target||evt.srcElement;
var value=oFile.value;
//若不存在则添加
if(oSel.innerHTML.indexOf(value)==-1){
oSel.options.add(new Option(
value,
value
));
} oBody.removeChild(oFile);
var oNewFile=document.createElement("input");
oNewFile.type="file";
oNewFile.name="file1"
oNewFile.id="file1"
oNewFile.onchange=fileSel;
oBody.appendChild(oNewFile);
}
</script>
</head>
<body>
<select id="sel1" multiple="multiple" size="10">
</select>
<br/>
<input type="file" id="file1"
onchange="fileSel(event)"/>
</body>
</html>