gpt4 book ai didi

javascript - 表中复选框的jquery验证代码

转载 作者:行者123 更新时间:2023-11-30 07:55:23 24 4
gpt4 key购买 nike

Image of skills required从上图中我添加了更多功能,所以我的问题是对于每一项技能 GD(或)PI(或)两个复选框都必须是强制性的。(必须至少选中一个复选框)我怎样才能做到这一点?这是我的 html:

<a class="text-center btn btn-danger addSkills">+ Add Skills</a>
<input class="selectGdSkill" type="checkbox" count="0" id="skill[0][gdskill]" name="skill[0][gdskill]">
<input class="selectPiSkill" type="checkbox" count="0" id="skill[0][piskill]" name="skill[0][piskill]">

这是添加更多功能的代码:

var skillcount = 1;
$(".addSkills").click(function () {
$('#jobSkills tr:last').after('<tr>
<td><input class="searchskill" count="' + skillcount + '" id="skill_' + skillcount + '_title" name="skill[' + skillcount + '][title]" type="text" autocomplete="off"></td><td><input count="' + skillcount + '" id="skill_' + skillcount + '_weightage" name="skill[' + skillcount + '][weightage]" type="text" autocomplete="off"></td>
<td><select class="wp-form-control" name="skill[' + skillcount + '][type]"><option value="0">Select Test Type</option><option value="1">Practice Test</option><option value="2">Qualifying</option></select></td>
<td><input class="selectGdSkill" type="checkbox" count="' + skillcount + '" id="skill[' + skillcount + '][gdskill]" name="skill[' + skillcount + '][gdskill]"></td>
<td> <input class="selectPiSkill" type="checkbox" count="' + skillcount + '" id="skill[' + skillcount + '][piskill]" name="skill[' + skillcount + '][piskill]"></td>
<td><span class="removeSkill" id="' + skillcount + '" ><a style="color:red">Remove</a></span></td>
</tr>');
skillcount++;
});

帮我解决问题:https://jsfiddle.net/r359b453/6/

最佳答案

这是你的 HTML 我已经更改了输入框 ID 并把你的表 <div id="myDiv">
<table id="tableID">
<tr>
GD<input class="selectGdSkill" type="checkbox" id="selectGdSkill_0">
PI<input class="selectPiSkill" type="checkbox" id="selectPiSkill_1">
</tr>
<br>
<tr>
GD<input class="selectGdSkill" type="checkbox" id="selectGdSkill_1">
PI<input class="selectPiSkill" type="checkbox" id="selectPiSkill_1">
</tr>
</table>
<button id="JobSubmit" class="btn btn-success text-center">SUBMIT JOB</button>
</div>

这是用于检查的 javascript 代码。

    $(document).ready(function(){
$("#JobSubmit").on("click",function(){
var IDs = [];
$("#myDiv").find("input").each(function(){ IDs.push(this.id); });
console.log(IDs);

$.each(IDs, function(i, value) {
if(!($("#"+value ).is(":checked"))){
alert("Atleast one checkbox has to select from every tr");
return false;
}

});

})
})

关于javascript - 表中复选框的jquery验证代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41277193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com