【发布时间】:2016-09-24 13:02:33
【问题描述】:
function showHide() {
var div = document.getElementById("hidden_div");
if (div.style.display == 'none') {
div.style.display = '';
} else {
div.style.display = 'none';
}
}
<form method="post" name="installer" onsubmit="showHide(); return false;">
<label>Home Keyword</label>
<br />Are you looking to live here?
<input id="checkbox" type="checkbox">
<br />Are you looking to rent?
<input id="checkbox" type="checkbox">
<br />
<input type="submit" value="Continue" name="submit" onsubmit="showHide()">
</form>
<div id="hidden_div" style="display:none">
<p>Show rest of the form here when the above form is submitted with no checkboxes ticked</p>
</div>
<div id="sorry_div" style="display:none">
<p>Sorry, we can't continue with your application.</p>
</div>
如果两个复选框都为空(在提交/继续按钮之后),我正在尝试显示表单的其余部分。但是,目前无论勾选了多少,它都会显示。
在此之后,如果两者都被勾选,我将如何处理即将出现的消息:抱歉,我们无法继续或类似?
这是相对容易制作还是相当复杂?
我有以下 HTML:
<form method="post" name="installer" onsubmit="showHide(); return false;">
<label>Home Keyword</label>
<br />
Are you looking to live here? <input id="checkbox" type="checkbox"><br />
Are you looking to rent? <input id="checkbox" type="checkbox"><br />
<input type="submit" value="Continue" name="submit" onsubmit="showHide()">
</form>
<div id="hidden_div" style="display:none">
<p>Show rest of the form here when the above form is submitted with no checkboxes ticked </p>
</div>
<div id="sorry_div" style="display:none">
<p>Sorry, we can't continue with your application.</p>
</div>
JS:
function showHide() {
var div = document.getElementById("hidden_div");
if (div.style.display == 'none') {
div.style.display = '';
}
else {
div.style.display = 'none';
}
}
【问题讨论】:
标签: javascript jquery html forms submit