如果主管已使用 2 个字段签名,我将尝试禁用表单的一部分。 问题是效果太好了。它禁用新表单上的部分。为简洁起见,这里有 2 个字段,这些字段的隐藏值和 jquery 脚本。
这是添加新表单或记录时字段的代码。 这两种形式位于具有 id 超节的 div 中。 这是 2 个字段的 html 首先是表单中字段的隐藏值,然后是字段本身的 html。
<div id="supersection" style="border: none;">
<input type="hidden" name="supersignoff" value="0"/>
<input type="hidden" name="superdeclare" value="0"/>
<label class="padd2left" for="supersignoff">
<input type="checkbox" value="1" id="supersignoff" name="supersignoff" />
Complete and sign</label>
<label for="superdeclare">
<input type="checkbox" value="1" id="superdeclare" name="superdeclare" />
I have completed with the best info from all parties</label>
下面是 jquery 脚本。这将禁用整个部分。
$(function(){
var signoff = $("#supersignoff").val();
var sdeclare = $("#superdeclare").val()
if(signoff=="1" && sdeclare=="1"){
$("#supersection *").prop("disabled",true);
}
})
即使该部分是新表单,该部分仍被禁用。
有什么想法吗?
最佳答案
$(function(){
var signoff = $("#supersignoff").prop('checked');
var sdeclare = $("#superdeclare").prop('checked')
if(signoff && sdeclare){
$("#supersection *").prop("disabled",true);
}
});
.prop('checked') 将为您提供复选框是否已选中的状态,但不是 .val()
。
关于javascript - 仅当 2 个字段的值为 1 并选中时才尝试禁用表单的 div 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27065715/