代码如下: 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()"/>
"document.getElementById('t1').values = '';"楼主写错了,所以文本框清空不了.红色部分改为: value
var tt=document.fileForm.sele; var tiem=document.createElement("OPTION"); tiem.value=val; //先给option赋值 tiem.innerText=val; tt.options.add(tiem); //再添加 document.fileForm.t1.value="" var v=document.fileForm.t1.value;
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()"/>
var tiem=document.createElement("OPTION"); tiem.value=val; //先给option赋值
tiem.innerText=val; tt.options.add(tiem); //再添加
document.fileForm.t1.value=""
var v=document.fileForm.t1.value;