select2的必填项为false时,jquery无效
<p>如何使用jQuery使select2的必填字段为false?我想使用jQuery使每个select2都要求= false并将其禁用。</p>
<p>我尝试了这个......但是$('#accodeformheader').find('input, select').attr('required', false);不起作用。
有没有办法使select2的“required”= false?</p>
<pre class="brush:php;toolbar:false;">$(document).ready(function() {
$('#idtask').change(function() {
var taskVal = $(this).val();
console.log("当前任务值", taskVal);
if (taskVal === "Grass") {
document.getElementById("idspeakerdetailsdiv").style.display = "block";
}
else {
document.getElementById("idspeakerdetailsdiv").style.display = "none";
}
})
$('.lexemeview').click(function() {
$('#accodeformheader').find('input, select').attr('disabled', true);
$('#accodeformheader').find('input, select').attr('required', false);
document.getElementById("accodeformheader").style.display = "none";
buttonType = $(this).attr("id")
activeform(buttonType)
$('#formdisplay').find('input, select').attr('disabled', true);
$('#editbutton').attr('hidden', false);
var accode = $(this).attr("id");
console.log(accode)
$.getJSON("{{url_for('karya_bp.getonespeakerdetails')}}", {
asycaccesscode:String(accode)
}, function(data) {
console.log(data)
metadata = data.speakerdetails.current.workerMetadata
console.log (metadata)
$('#accesscode').attr('value', accode)</pre>
<pre class="brush:php;toolbar:false;"><div id="accodeformheader" style="display: block;">
<div class="form-group">
<label for="idaccesscodefor">Access Code For:</label><br>
<select class="accesscodefor" id="idaccesscodefor" name="accesscodefor" style="width:55%" required></select><br>
</div>
<div class="form-group">
<标签=“idtask”>任务:标签>
<select class="task" id="idtask" name="task" style="width:55%" required></select><br>
<div id="uploadaccode" style="display: block;"></div>
<div class="form-group">
<标签类=“col-form-label”>名称:标签>
<div class="form-group">
<标签=“sgender”>性别:</label> <br>
<选择 class="gender" id="idgender" name="sgender" style="width:55%" 必需>
</选择><br>
<div class="form-group">