1
隐藏我有一个使用jQuery的形式隐藏了不相关的领域,除非满足某些条件的表单元素:
<form action="thepage.php id="subform" method="post">
<h2>
Select a Drawing Type:
</h2>
<div>
<input type="radio" name="drawingType" tabindex="10" value="1"/>Drawing 1
<input type="radio" name="drawingType" value="2"/>Drawing 2
<input type="radio" name="drawingType" value="3"/>Drawing 3
<input type="radio" name="drawingType" value="4"/>Drawing 4
</div>
<p class="drawingInput drawX">
Is this drawing related to an old drawing?
<input type="radio" name="revUp" tabindex="100" value="0"/>No
<input type="radio" name="revUp" value="1"/>Yes
</p>
<input type="submit" name="submitted" value="New Drawing" />
</form>
随着jQuery的:
$('.drawingInput').hide;
$('input:[name="drawingType"]').change(function(){
if ($(this).val()==1){
$('.drawingInput').hide();
$('.drawX').show();
} else if ($(this).val()==2){
$('.drawingInput').hide();
$('.drawX').show();
} else if ($(this).val()==3){
$('.drawingInput').hide();
} else if ($(this).val()==4){
$('.drawingInput').hide();
}
});
因此,当选择绘图1或2时,显示下一个输入按钮。用户然后选择revUp
字段,并提交,一切工作正常。但是,如果从未透露p
,例如未在第一个收音机框中选择值1或2,则revUp
永远不会是$ _POST'ed,证据为var_dump($_POST)
。
如果用户从未看到它,我如何检索revUp
的值?它在var_dump可见时显示,但在从未选择时显示。控制台阅读器也是如此,检查发送的标题。
我已经在Chrome和Firefox(最新版本)中尝试过它并获得相同的响应。我正在使用逻辑语句的值。我宁愿确定基于'revUp'的下一步行动,而不是添加额外的逻辑。它会更便携。不透明的想法很有趣,但语义上不正确。 – Sablefoste