當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS 控制RadioButtonList 获得上传文件类型后选中
生活随笔
收集整理的這篇文章主要介紹了
JS 控制RadioButtonList 获得上传文件类型后选中
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Code
?1<asp:FileUpload?ID="UploadFile"?runat="server"?onchange="javascript:Change(this.value);"?/>?2????????
?3?????????<%--<asp:FileUpload?ID="UploadFile"?runat="server"?OnChange="Change(this.value);"?/>也可以使用這種方法調用JavaScript--%>
?4?????????
?5????????<asp:RadioButtonList?ID="ImgType"?runat="server"?RepeatDirection="Horizontal">
?6????????????<asp:ListItem?Value="jpg">jpg</asp:ListItem>
?7????????????<asp:ListItem?Value="jpeg">jpeg</asp:ListItem>
?8????????????<asp:ListItem?Value="gif">gif</asp:ListItem>
?9????????????<asp:ListItem?Value="bmp">bmp</asp:ListItem>
10????????????<asp:ListItem?Value="swf">Flash</asp:ListItem>
11????????</asp:RadioButtonList>
?1<script?language="javascript"?type="text/javascript">
?2????????function?Change(value)
?3????????{
?4????????????
?5????????????var?theStrLen???=?value.length;
?6????????????//得到上傳文件所在的路徑的長度
?7????????????var?thePosition?=?value.lastIndexOf(".");
?8????????????//從底部開始查找?"."?這個字符
?9????????????var?fileType?=?value.substr(thePosition+1,theStrLen-1);
10????????????//獲得上傳文件的類型
11????????????var?RadioObject?=document.getElementById('<%=ImgType.ClientID%>');
12????????????//這個也可以用doucument.getElementById("ImgType")來得到,
13????????????//一般情況下應該使用?document.getElementById('<%=ImgType.ClientID%>')來得到這個Object;
14????????????var?RadioInput??=?RadioObject.getElementsByTagName("INPUT");
15????????????//因為WebControl在客戶端的顯示為HTML代碼,所以必須要依據客戶端的顯示查找"INPUT"
16????????????
17??????????????var?flag?=?true;
18??????????????
19??????????????for(var?i=0;i<RadioInput.length;i++)
20??????????????{
21????????????????if(RadioInput[i].value==fileType)
22????????????????{
23????????????????????RadioInput[i].checked=true;
24????????????????????flag=true;
25????????????????????break;//退出循環??????continue為中斷本次循環,進入下次循環
26????????????????}
27????????????????else
28????????????????{
29????????????????????flag=false;
30????????????????}
31??????????????}
32??????????????
33??????????????if(flag==false)
34??????????????{
35????????????????alert("文件類型不正確");
36????????????????return?false;
37??????????????}
?????????????????????else
????????????????????????return true;
38????????}
39????</script>
?
轉載于:https://www.cnblogs.com/Caceolod/archive/2007/06/15/784737.html
總結
以上是生活随笔為你收集整理的JS 控制RadioButtonList 获得上传文件类型后选中的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简化管理面向服务的应用程序的创建
- 下一篇: 高质量c/c++编程(5)