ホームページ  >  に質問  >  本文

select2の必須項目がfalseの場合、jqueryは無効となります

<p>jQuery を使用して select2 の必須フィールドを false にする方法は? jQueryを使用してすべてのselect2をrequire=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 === "草") { document.getElementById("idspeakerdetailsdiv").style.display = "ブロック"; } それ以外 { 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") アクティブフォーム(ボタンタイプ) $('#formdisplay').find('input, select').attr('disabled', true); $('#editbutton').attr('hidden', false); var acode = $(this).attr("id"); コンソール.ログ(accode) $.getJSON("{{url_for('karya_bp.getonespeakerdetails')}}", { asycaccesscode:文字列(accode) }、関数(データ) { コンソール.ログ(データ) メタデータ = data.speakerdetails.current.workerMetadata console.log (メタデータ) $('#accesscode').attr('value', accode)</pre> <pre class="brush:php;toolbar:false;"><div id="accodeformheader" style="display: block;"> <div class="フォームグループ"> <label for="idaccesscodefor">アクセス コード:</label><br> <select class="accesscodefor" id="idaccesscodefor" name="accesscodefor" style="width:55%" 必須></select><br> </div> <div class="フォームグループ"> <label for="idtask">タスク :</label><br> <select class="task" id="idtask" name="task" style="width:55%" 必須></select><br> </div> <div id="uploadaccode" style="display: block;"></div> </div> <div class="フォームグループ"> <label class="col-form-label">名前:</label> <input type="text" class="form-control" id="idname" name="sname" placeholder="--スピーカー名--" style="width:55%" value="" 必須 > </div> <div class="フォームグループ"> <label for="sagegroup">年齢層: </label> <br> <class="age" id="idage" name="sagegroup" style="width:55%" を選択してください> </select><br> </div> <div id="idspeakerdetailsdiv" style="表示: なし;"> <div class="フォームグループ"> <label for="sgender">性別: </label> <br> <select class="gender" id="idgender" name="sgender" style="width:55%" 必須> </select><br> </div> <div class="フォームグループ"> <label for="educationalevel">教育レベル: </label> <br> <select class="educationlvl" id="idelevel" name="educationalevel" style="width:55%" 必須> </select><br> </div> <div class="フォームグループ"> <label for="moe12">教育媒体 (12 日まで): </label><br> <select class="educationmediumupto12" id="idmediumpre" name="moe12" multiple="multiple" style="width:55%" 必須> </select><br> </div> <div class="フォームグループ"> <label for="moea12">教育中期 (12 日以降): </label><br> <select class="educationmediumafter12" id="idmediumpost" name="moea12" multiple="multiple" style="width:55%" 必須> </select><br> </div> </div> <button type="button" id="closebutton" class="btn btn-secondary" data-dismiss="modal">閉じる</button> <input type="submit" value="Submit">

</フォーム> </div><<

P粉775788723P粉775788723412日前601

全員に返信(1)返信します

  • P粉762730205

    P粉7627302052023-09-04 00:50:24

    「required」属性が必要ない場合は、単純に削除できます

    リーリー

    リセットする場合は、次の手順に従ってください:

    リーリー

    ID またはクラスに基づいて特定の select2 ドロップダウンを削除する場合は、次の手順に従ってください:

    リーリー

    クラス名を使用:

    リーリー

    同様に、次のように ID とクラスに基づいて設定できます:

    リーリー

    クラス名を使用:

    リーリー

    あなたの質問を理解し、正しい答えができたことを願っています。

    返事
    0
  • キャンセル返事