Posted on 2010-07-04 18:51
幻海藍夢 閱讀(1066)
評論(2) 編輯 收藏 所屬分類:
JS
原文:
http://zhidao.baidu.com/question/91138063.html?fr=qrl&cid=93&index=2&fr2=query
問題補充:我要在同一網頁內用select聯動幾個form表單,不跳轉頁面的?
我建了一個select菜單,想聯動幾個表單,代碼是:?
<select?name=s1>?
<option?value='week'>一周</option>?
<option?value='month'>一月</option>?
<option?value='year'>一年</option>?
</select>?
我建了三個表單form,代碼如下:?
表單一:?
<form?name=formWeek>?
<table>?
<tr>?
<td>請輸入一周的次數:</td>?
<td><input?type=text?size=3></td>?
</tr>?
</table>?
</form>?

表單二:?
<form?name=formMonth>?
<table>?
<tr>?
<td>請輸入一月的次數:</td>?
<td><input?type=text?size=3></td>?
</tr>?
</table>?
</form>?

表單三:?
<form>?
<table>?
<tr>?
<td>請輸入一年的次數:</td>?
<td><input?type=text?size=3></td>?
</tr>?
</table>?
</form>?
全部代碼如下,測試通過.

<html>
<head><title>切換</title></head>
<body>
<select?name="s1"?onchange="changeform(this.value)">
<option?value='week'>一周</option>?
<option?value='month'>一月</option>?
<option?value='year'>一年</option>?
</select>?

<br?/>
<div?id="form1">
<form?name=formWeek>?
<table>?
<tr>?
<td>請輸入一周的次數:</td>?
<td><input?type=text?size=10></td>
</tr>?
</table>?
</form>?
</div>

<div?id="form2">?
<form?name=formMonth>?
<table>?
<tr>?
<td>請輸入一月的次數:</td>?
<td><input?type=text?size=10></td>?
</tr>?
</table>?
</form>
</div>


<div?id="form3">
<form>?
<table>?
<tr>?
<td>請輸入一年的次數:</td>?
<td><input?type=text?size=10></td>?
</tr>?
</table>
</form>
</div>
<script?type="text/javascript">

$d=function(id)
{return?document.getElementById(id);}
fhidden($d("form2"),$d("form3"),$d("form1"));
function?fhidden(str1,str2,str3)


{
str1.style.display="none";
str2.style.display="none";
str3.style.display="";
}

function?changeform(v)


{
switch?(v)


{
case?"month":fhidden($d("form1"),$d("form3"),$d("form2"));break;
case?"year":fhidden($d("form1"),$d("form2"),$d("form3"));break;
default:fhidden($d("form2"),$d("form3"),$d("form1"));break;
}
}
</script>
</body>
</html>?