亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

啟用/禁用選擇/下拉菜單和下拉單選按鈕?

啟用/禁用選擇/下拉菜單和下拉單選按鈕?

收到一只叮咚 2022-10-21 15:10:03
我正在嘗試啟用/禁用單選按鈕并在選擇的下拉列表中選擇/下拉。Jsfiddle 鏈接例如:如果persons僅被選中name="persons"(Anthony 和 Paul)并且person dropdown必須可供選擇并且必須禁用 Rest     <select class="browser-default" id="type" name="type">        <option value="persons">persons</option>        <option value="animals">animals</option>        <option value="fruits">fruits</option>        </select>        <br/>        <label><input type="radio" name="fruits" value="apple" id="apple" title="">Apple</label>        <br/>        <label><input type="radio" name="fruits" value="banana" id="banana" title="">Banana</label>        <br/>        <label><input type="radio" name="animals" value="dog" id="dog" title="">Dog</label>        <br/>        <label><input type="radio" name="animals" value="cat" id="cat" title="">Cat</label>        <br/>        <label><input type="radio" name="persons" value="anthony" id="anthony" title="">Anthony</label>        <br/>        <label><input type="radio" name="persons" value="paul" id="paul" title="">Paul</label>        <br/>        <select class="browser-default" id="persons1" name="persons">        <option value="1">Person Dropdown</option>        </select>        <br/>         <select class="browser-default" id="animals1" name="animals">        <option value="1">Animals Dropdown</option>        </select>        <br/>         <select class="browser-default" id="fruits1" name="fruits">        <option value="1">Fruits Dropdown</option>        </select>        <br/> 我試過的:只有單選按鈕沒有選擇/下拉,    $(document).ready(function() {    $("select").change(function() {        $("input").prop("checked", false);        $("input").prop('disabled', false);        $("input[type='radio']").prop("disabled", true);        $("input[name='" + $(this).val() + "']").prop("disabled", false);    }).trigger("change");    })
查看完整描述

2 回答

?
www說

TA貢獻1775條經驗 獲得超8個贊

 function disabled_all(){

  $('input[name="fruits"],input[name="animals"],input[name="fruits"], select[name="persons"],select[name="animals"],select[name="fruits"]').prop('disabled', true);

  }

 

 disabled_all();

 

 $('.browser-default').on('change', function () {

    var type = $(this).val();

    disabled_all();

    $('input[name="' + type + '"], select[name="' + type + '"]').prop('disabled', false);

}).trigger('chnage');

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<select class="browser-default" id="type" name="type">

        <option value="persons">persons</option>

        <option value="animals">animals</option>

        <option value="fruits">fruits</option>

        </select>


        <br/>


        <label><input type="radio" name="fruits" value="apple" id="apple" title="">Apple</label>

        <br/>

        <label><input type="radio" name="fruits" value="banana" id="banana" title="">Banana</label>

        <br/>


        <label><input type="radio" name="animals" value="dog" id="dog" title="">Dog</label>

        <br/>

        <label><input type="radio" name="animals" value="cat" id="cat" title="">Cat</label>

        <br/>



        <label><input type="radio" name="persons" value="anthony" id="anthony" title="">Anthony</label>

        <br/>

        <label><input type="radio" name="persons" value="paul" id="paul" title="">Paul</label>

        <br/>


        <select class="browser-default" id="persons1" name="persons">

        <option value="1">Person Dropdown</option>

        </select>

        <br/> 


        <select class="browser-default" id="animals1" name="animals">

        <option value="1">Animals Dropdown</option>

        </select>

        <br/> 


        <select class="browser-default" id="fruits1" name="fruits">

        <option value="1">Fruits Dropdown</option>

        </select>

        <br/>


查看完整回答
反對 回復 2022-10-21
?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

您可以遍歷所有具有相同名稱并啟用該單選按鈕的單選按鈕。此外,啟用選擇框使用 $("select[name='" + $(this).val() + "']").prop("disabled", false); 。


演示代碼:


$(document).ready(function() {


  $("#type").change(function() {

  //disable other select

   $('select:not(#type)').prop("disabled", true);

    $("input").prop("checked", false);

    $("input").prop('disabled', false);

    $("input[type='radio']").prop("disabled", true);

    //looping through all inputs

  $("input[name='" + $(this).val() + "']").each(function(){

   $(this).prop("disabled", false); //remove disable

  })

  //remove disabled from slect

 $("select[name='" + $(this).val() + "']").prop("disabled", false);

 


  }).trigger("change");

})

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

<select class="browser-default" id="type" name="type">

  <option value="persons">persons</option>

  <option value="animals">animals</option>

  <option value="fruits">fruits</option>

</select>


<br/>


<label><input type="radio" name="fruits" value="apple" id="apple" title="">Apple</label>

<br/>

<label><input type="radio" name="fruits" value="banana" id="banana" title="">Banana</label>

<br/>


<label><input type="radio" name="animals" value="dog" id="dog" title="">Dog</label>

<br/>

<label><input type="radio" name="animals" value="cat" id="cat" title="">Cat</label>

<br/>



<label><input type="radio" name="persons" value="anthony" id="anthony" title="">Anthony</label>

<br/>

<label><input type="radio" name="persons" value="paul" id="paul" title="">Paul</label>

<br/>


<select class="browser-default" id="persons1" name="persons">

  <option value="1">Person Dropdown</option>

</select>

<br/>


<select class="browser-default" id="animals1" name="animals">

  <option value="1">Animals Dropdown</option>

</select>

<br/>


<select class="browser-default" id="fruits1" name="fruits">

  <option value="1">Fruits Dropdown</option>

</select>

<br/>


查看完整回答
反對 回復 2022-10-21
  • 2 回答
  • 0 關注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號