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

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

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

<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>請(qǐng)輸入一周的次數(shù):</td>?
<td><input?type=text?size=10></td>
</tr>?
</table>?
</form>?
</div>

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


<div?id="form3">
<form>?
<table>?
<tr>?
<td>請(qǐng)輸入一年的次數(shù):</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>?