當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript获取文本框内容,select选择的值(jsp内实现)
生活随笔
收集整理的這篇文章主要介紹了
JavaScript获取文本框内容,select选择的值(jsp内实现)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1. 實例代碼
JavaScript代碼:
<script language="JavaScript"> function check(theForm){if(theForm.xh.value.length!=11){alert("學號必須為11位!");theForm.xh.focus();return (false);}var myselect = document.getElementById("bj"); //獲取select對象bjvar index = myselect.selectedIndex; //獲取被選中的索引var banHao = myselect.options[index].value; //獲取被選中的值(班級編碼)var xx=document.getElementById("xh").value;xx=xx.substring(0,9);if(banHao!=xx){alert("所選班級與學號沖突,學號=班級編號+序號!");theForm.xh.focus();return (false);}if(theForm.xm.value==""){alert("請輸入姓名!");theForm.xm.focus();return (false);} } </script>JSP:
<select name="bj" id="bj" > <% while(rs.next()){ String bjbh=rs.getString("bjbh");String bjmc=rs.getString("bjmc");%><option value="<%=bjbh%>" ><%=bjmc %></option><%} %></select></td></tr> <tr><td>學號</td><td> <input type="text" name="xh" id="xh" /></td></tr>2. 重點
javascript中的theForm.xh.value可以進行
字符串長度的比較theForm.xh.value.length!=11 和
是否為空的比較theForm.xh.value=="",使用語句theForm.xh.value="xxxx"時無效。
從表單獲取文本框內(nèi)容和選擇的值:
var myselect = document.getElementById("bj"); //獲取select對象bjvar index = myselect.selectedIndex; //獲取被選中的索引var banHao = myselect.options[index].value; //獲取被選中的值(班級編碼)var xx=document.getElementById("xh").value;//獲取id為xh的組件的值總結(jié)
以上是生活随笔為你收集整理的JavaScript获取文本框内容,select选择的值(jsp内实现)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用原生JS写一个网页版的2048小游戏(
- 下一篇: js android 通讯录,JavaS