我想在完成後隱藏第一個表單,然後在第一個表單的同一位置顯示第二個表單,之後我會將輸入的信息發送到電子郵件。我試圖只顯示一個窗體完成後,然後形式2,窗體2不會顯示?
社區可以提出我需要改變我的代碼,謝謝。
function showhide() {
var myDiv = document.getElementById("form2");
var div = document.getElementById("form1");
if (div.style.display !== "none") {
div.style.display = "none";
} else {
div.style.display = "form2";
}
};
#form2 {
display: none;
}
<div class="col-md-4" id="form1">
<div class="panel panel-default">
<div class="panel-heading">
<h3>Help is here!</h3>
</div>
<div class="panel-body">
<!-- HTML Form (wrapped in a .bootstrap-iso div) -->
<div class="bootstrap-iso">
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-3 col-xs-12">
<form method="post">
<div class="form-group ">
<label class="control-label " for="name">
First name
</label>
<input class="form-control" id="name" name="name" type="text" required/>
</div>
<div class="form-group ">
<label class="control-label " for="name1">
Last name
</label>
<input class="form-control" id="name1" name="name1" type="text" required/>
</div>
<div class="form-group ">
<label class="control-label " for="tel">
Telephone #
</label>
<input class="form-control" id="tel" name="tel" type="text" required/>
</div>
<div class="form-group ">
<label class="control-label requiredField" for="email">
Email
<span class="asteriskField">
*
</span>
</label>
<input class="form-control" id="email" name="email" type="text" required/>
</div>
<div>
<button id="button" onclick="showhide()">Click Me</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="col-md-12 " id="form2">
<div class="panel panel-default">
<div class="panel-heading">
<h3>One more step</h3>
</div>
<div class="panel-body">
<!-- HTML Form (wrapped in a .bootstrap-iso div) -->
<div class="bootstrap-iso">
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-3 col-xs-12">
<form method="post">
<div class="form-group ">
<label class="control-label " for="state">
What state are you in?
</label>
<select class="form-control">
<option>Alabama</option>
<option>Alaska</option>
<option>Arizona</option>
<option>Arkansas</option>
<option>California</option>
<option>Colorado</option>
<option>Connecticut</option>
<option>Delaware</option>
<option>Florida</option>
<option>Georgia</option>
<option>Hawaii</option>
<option>Idaho</option>
<option>Illinois Indiana</option>
<option>Iowa</option>
<option>Kansas</option>
<option>Kentucky</option>
<option>Louisiana</option>
<option>Maine</option>
<option>Maryland</option>
<option>Massachusetts</option>
<option>Michigan</option>
<option>Minnesota</option>
<option>Mississippi</option>
<option>Missouri</option>
<option>Montana Nebraska</option>
<option>Nevada</option>
<option>New Hampshire</option>
<option>New Jersey</option>
<option>New Mexico</option>
<option>New York</option>
<option>North Carolina</option>
<option>North Dakota</option>
<option>Ohio</option>
<option>Oklahoma</option>
<option>Oregon</option>
<option>Pennsylvania Rhode Island</option>
<option>South Carolina</option>
<option>South Dakota</option>
<option>Tennessee</option>
<option>Texas</option>
<option>Utah</option>
<option>Vermont</option>
<option>Virginia</option>
<option>Washington</option>
<option>West Virginia</option>
<option>Wisconsin</option>
<option>Wyoming</option>
</select>
</div>
<div class="form-group ">
<label class="control-label " for="owe">
How much do you owe on your house?
</label>
<select class="form-control">
<option>Select one</option>
<option>owe less than $75,000 on home</option>
<option>owe between $75,000 to 100,000</option>
<option>owe between $100,000 to $200,000</option>
<option>owe between $300,000 to $400,000</option>
<option>owe between $400,000 to $500,000</option>
<option>owe more than $500,000 on home</option>
</select>
</div>
<div class="form-group ">
<label class="control-label " for="lender">
Who is your lender?
</label>
<input class="form-control" id="lender" name="lender" type="text" />
</div>
<div class="form-group ">
<label class="control-label requiredField" for="foreclose-date">
Is there a foreclosure sales auction date set?
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">Yes
</label>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">No
</label>
</label>
</div>
<div class="form-group ">
<label class="control-label " for="property">
Property address
</label>
<input class="form-control" id="property" name="property" type="text" />
</div>
<div class="form-group">
</div>
<div>
<button class="btn btn-primary " name="submit" type="submit">
Submit
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
好一件事「窗口2」是不是'div.style.display'有效的設置 - 你爲什麼不重命名變量' form1'和'form2'而不是'myDiv'和'div',那麼你可以'form1.style.display ='none''和'form2.style.display ='block''等。 –
@ Two-BitAlchemist - 即使它無效,它仍應顯示它。 – Derek
@OliverQueen但是他也在混合var名稱 - 'div'是form1,你看。在CSS中設置form2'display:none',然後從不對'myDiv'做任何事情,所以它保持這種狀態。 –