Nol*_*lan 1 forms jquery field
我有一个简单的表单,有四个选择字段.如果在任何表单域中选择"是",则需要禁用"提交"按钮并显示隐藏的div.这是我的标记示例:
<form>
I have read the information on the product(s)<select name="field4"> <option value="Yes">Yes</option> <option value="No">No</option> </select>
Do you have any allergies to any ingredients in product(s)?
<select name="field5"><option value="Yes">Yes</option> <option value="No">No</option> </select>
Are you pregnant?
<select name="field6"> <option value="Yes">Yes</option> <option value="No">No</option> </select>
Have you ever used this type of product and had undesirable results?
<select name="field7"> <option value="Yes">Yes</option> <option value="No">No</option> </select>
<input name="cmdSubmit" type="submit" value="Submit" />
</form>
<div style="display:none;">Hidden div only to appear if any of the four dropdowns are marked YES.</div>
Run Code Online (Sandbox Code Playgroud)
感谢您对此的帮助.我是一个jquery新手,我尽力学习.
我不完全理解你建立表单的方式和你的要求的业务逻辑,但......基于你在这里所说的内容,我会做的.
.
checkOptions();
$("select").change(checkOptions);
function checkOptions() {
var yesFound = false;
$("select").each(function(index, element) {
if ( $(element).val() == "Yes" ) {
yesFound = true;
}
});
if (yesFound) {
$("#hidden-div").show();
$("input[type=Submit]").attr("disabled","disabled");
} else {
$("#hidden-div").hide();
$("input[type=Submit]").removeAttr("disabled");
};
}
Run Code Online (Sandbox Code Playgroud)
稍加修改的HTML:
<form>
<select name="field4">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select> I have read the information on the product(s)<br/>
<select name="field5">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select> Do you have any allergies to any ingredients in product(s)?<br/>
<select name="field6">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select> Are you pregnant?<br/>
<select name="field7">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select> Have you ever used this type of product and had undesirable results?<br/>
<br/>
<input name="cmdSubmit" type="submit" value="Submit" />
</form>
<div id="hidden-div" style="display:none;">Hidden div only to appear if any of the four dropdowns are marked YES.</div>
Run Code Online (Sandbox Code Playgroud)
负载:

所有选项'不'只有一个:

所有选项'是':

| 归档时间: |
|
| 查看次数: |
5380 次 |
| 最近记录: |