通過下拉框的值來確定輸入框是否可以為空的代碼
更新時(shí)間:2011年10月18日 10:40:33 作者:
本節(jié)只是為了做一個(gè)記載,實(shí)現(xiàn)一個(gè)簡(jiǎn)單的驗(yàn)證是否需要預(yù)占下來框有是和否兩個(gè)值,當(dāng)選擇“是”時(shí),資源預(yù)占原因輸入框必須輸入值,否則不能跳轉(zhuǎn),當(dāng)選“否”時(shí),不需要驗(yàn)證資源預(yù)占原因輸入框
有兩個(gè)文件a.html和b.html,a.html 即下面的代碼,b.html只是為了驗(yàn)證通過時(shí)候一個(gè)跳轉(zhuǎn)頁面,不做任何代碼編寫
因?yàn)閍.html用的是相對(duì)路徑,所以要想程序能正常運(yùn)行,b.html文件必須和a.html放在同一個(gè)目錄下。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script type="text/javascript">
function verify(){
var isNeed=document.getElementById("isNeed").value;
if(isNeed==1){
var reason=document.getElementById("reason").value;
if(reason==""||reason==null){
alert("預(yù)占資源原因不能為空");
}else{
window.location.href("a.html");
}
}else{
window.location.href("b.html");
}
}
</script>
<body>
是否需要預(yù)占資源
<select id="isNeed">
<option value="1">是</option><!--通過getElementById()的方法來取到下拉框的值,所以 必須有個(gè)id,name可以不要-->
<option value="0" selected>否</option>
</select>
<input type="text" id="reason"/>
<input type="button" value="提交" onclick="verify()"/>
</body>
</html>
因?yàn)閍.html用的是相對(duì)路徑,所以要想程序能正常運(yùn)行,b.html文件必須和a.html放在同一個(gè)目錄下。
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script type="text/javascript">
function verify(){
var isNeed=document.getElementById("isNeed").value;
if(isNeed==1){
var reason=document.getElementById("reason").value;
if(reason==""||reason==null){
alert("預(yù)占資源原因不能為空");
}else{
window.location.href("a.html");
}
}else{
window.location.href("b.html");
}
}
</script>
<body>
是否需要預(yù)占資源
<select id="isNeed">
<option value="1">是</option><!--通過getElementById()的方法來取到下拉框的值,所以 必須有個(gè)id,name可以不要-->
<option value="0" selected>否</option>
</select>
<input type="text" id="reason"/>
<input type="button" value="提交" onclick="verify()"/>
</body>
</html>
相關(guān)文章
js數(shù)據(jù)驗(yàn)證集合、js email驗(yàn)證、js url驗(yàn)證、js長(zhǎng)度驗(yàn)證、js數(shù)字驗(yàn)證等簡(jiǎn)單封裝
js數(shù)據(jù)驗(yàn)證集合,進(jìn)行了封裝推薦大家學(xué)習(xí)使用。里面有例子測(cè)試代碼。2010-05-05javascript實(shí)現(xiàn)上傳圖片前的預(yù)覽(TX的面試題)
javascript實(shí)現(xiàn)上傳圖片前的預(yù)覽(TX的面試題)...2007-08-08js模擬權(quán)限選擇實(shí)現(xiàn)代碼(select操作)
權(quán)限選擇頁面,選擇、撤回、全部選擇、全部撤回2012-02-02js select 標(biāo)簽選定項(xiàng)的值獲取代碼
用js獲取當(dāng)前選定的select的值的函數(shù)2009-03-03