我的名字是Michael Toscano。我目前正在爲學校開展一個3層的項目,但是我被困在了一個看似微不足道的步驟上。現在,我試圖通過單擊一個按鈕來隱藏各個HTML表單,並通過單擊另一個按鈕來顯示它們。 HTML頁面上只有兩種形式。如果我嘗試隱藏第二個表單,現在我的工作方式是,但是如果我嘗試僅隱藏第一個表單,它會隱藏整個頁面,除了頁面頂部的兩個按鈕(兩個表單)之外。我想,也許我意外地把第二種形式放在第一種形式(如果可能的話),但在查看我的代碼後,它看起來(至少對我來說)就像我終止了第一種形式。總之,整個HTML文件如下:使用javascript隱藏/顯示HTML表單(在按鈕上按下)
<!DOCTYPE html>
<html><head>
<button type=button id=f1 onclick="func(1)">Order Form</button>
<button type=button id=f2 onclick="func(2)">Retrieval Form</button>
<script type="text/javascript">
function func(a) {
if(a==1) {
document.getElementById("order").style.display="none";
}
if(a==2) {
document.getElementById("order").style.display="block";
}
}
</script>
<script type="text/javascript">
function showValue(newValue)
{
document.getElementById("range").innerHTML=newValue;
}
</script>
</head>
<body>
<form id=order action=form.php >
<p><center>Name: <input type=text
name="name"
placeholder="Enter Your Name"
required
autocomplete="on"></center><br>
<center>Email: <input type=text
name="email"
placeholder="Enter Your Email"
required
autocomplete="off"></center><br>
<center>Password: <input type=text
name="password"
placeholder="15 Characters Or Less"
required
autocomplete="off"></center><br>
<center>Address: <input type=text
name="address"
placeholder="Enter Your Address"
required
autocomplete="off"></center><br>
<center>Laptops: <input type=range
name=laptop
value=0
min=0
max=10
onChange="showValue(this.value)">
<center>Monitors: <input type=range
name=monitor
value=0
min=0
max=10
onChange="showValue(this.value)">
<center>Mouses: <input type=range
name=mouse
value=0
min=0
max=10
onChange="showValue(this.value)">
<center>Keyboards: <input type=range
name=keyboard
value=0
min=0
max=10
onChange="showValue(this.value)">
<br>
<br>
<center>Shipping Carrier: <SELECT name="delivery">
<option value="fedex">FEDEX</option>
<option value="ups">UPS</option>
</SELECT></center>
<br>
<center>Would you like an email receipt?<br>
<center>Yes <input type="radio" name="group1" value=1> No
<input type="radio" name="group1" value=0 checked></center><br>
<br>
<center><input type=submit value="Submit Order"></center></p>
</form>
<form id=retrieve action=form2.php>
First Name: <input type=text name=first><br>
Last Name: <input type=text name=last><br>
Password: <input type=password name=p1><br>
Retype Password: <input type=password name=p2><br>
<input type=submit>
</form>
</body>
</html>
我想指出的是,我是相當新的HTML和JavaScript,所以我將不勝感激,如果一個簡要的解釋可以陪任何人的響應。謝謝大家。
謝謝你的迴應。你所說的一切(合併)已經幫助我解決了我的問題。你有沒有可能解釋爲什麼「連線」javascript事件? – Mike 2013-04-05 18:29:49
在那裏,我爲你提供了更多細節。 – ErikE 2013-04-05 18:59:05
非常感謝,非常感謝:) – Mike 2013-04-12 16:35:37