<tr >
<td style="width:80px;">文件类型<span style="color: red;">*</span>:</td>
<td style="width:360px;" colspan="3">
<input id="fileKind" name="fileKind" class="mini-combobox" data="fileKind"
required="true" onvaluechanged="fileKindChange"/></td>
</tr>
<tr >
<td style="width:80px;">上传文件<span style="color: red;">*</span>:</td>
<td style="width:160px;" colspan="3">
<input style="background:none; border:none; padding-left:0" id="file" name="file"
type="file" accept=".mp4" ></td>
</tr>
如上代码,初始文件可接受的文件类型为MP4
当文件类型发生变化时,同时动态变更file的accept属性的值
具体js方法如下
:(注意:在全局变量中,我已获取 文件类型 fileKind 控件,此处直接使用了)
//文件类型变化事件,修改文件选择器允许选择的文件类型
function fileKindChange(){
var uploadFile=document.getElementById("file");
uploadFile.setAttribute('accept','.'+fileKind.getValue());
}