必要和可选的输入我有一个接触的形式这样中隐藏的div
<form action="" method="POST">
<div>
<fieldset>
<p dir="rtl">
<label>case1</label>
<select id="Color" required="required">
<option value="">please select</option>
<option value="redd">sell</option>
<option value="greenn">rent</option>
</select>
</p>
</fieldset>
</div>
<div class="redd box">
<input dir="rtl" type="text" name="pricerange" required />
<input dir="rtl" type="text" name="room" />
</div>
<div class="greenn box">
<input dir="rtl" type="text" name="rentrange" required />
<input dir="rtl" type="text" name="morgage" />
</div>
<p dir="rtl"><input name="submit" type="submit" value="submit" /></p>
</form>
正如你看到的我显示或隐藏2格箱“REDD箱”和“greenn箱”基于用户在表单的开头从下拉列表中选择的值。正如你所看到的,我在这个div盒里需要输入和可选的输入。但是当我选择其中一个div时,我必须填写必填字段和可选字段,否则我无法提交我的表单。任何想法?谢谢
$(document).ready(function(){
$("#Color").change(function() {
$(this).find("option:selected").each(function(){
if($(this).attr("value")=="redd"){
$(".box").not(".redd").hide().find("input").prop("required", false);
$(".redd").show().find("input").prop("required", true);
}
else if($(this).attr("value")=="greenn"){
$(".box").not(".greenn").hide().find("input").prop("required", false);
$(".greenn").show().find("input").prop("required", true);
}
else{
$(".box").hide();
}
});
}).change();
});
真的不清楚具体问题是什么。你已经显示了代码,但没有解释它是什么或没有正确地执行 – charlietfl
显示的代码在这里很好地工作https://jsfiddle.net/81kLoc6t/ – charlietfl
我添加了一个新的部分给我无法理解的问题,但我的一个两天前朋友告诉我。我希望你们中的一个人能够理解它 – Malekian