第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

選擇“單選按鈕”中的一個選項(xiàng)時如何禁用其他選項(xiàng)?

選擇“單選按鈕”中的一個選項(xiàng)時如何禁用其他選項(xiàng)?

PHP
撒科打諢 2023-05-12 15:54:13
我試圖在選擇一個選項(xiàng)后立即禁用其他選項(xiàng),但使用 java 腳本我無法做到這一點(diǎn)。請幫我。到目前為止我已經(jīng)嘗試過 <?php     $answer = $exm->getAnswer($number);    if ($answer) {        while ($result = $answer->fetch_assoc()) {?>            <tr>                <td>                 <input id="question_radio" type="radio" name="ans" value="<?php echo $result['id']; ?>"/><?php echo $result['ans']; ?><script id="question_radio" type="text/javascript">$(":radio").click(function(){   var radioName = $(this).attr("ans"); //Get radio name  $(":radio[name='"+radioName+"']:not(:checked)").attr("disabled", true); //Disable all unchecked radios with the same name});                         </script>                </td>            </tr><?php } } ?>            <tr>              <td>                <input type="submit" name="submit" value="Next Question"/>                <input type="hidden" name="number" value="<?php echo $number; ?>" />                </td>            </tr>
查看完整描述

2 回答

?
子衿沉夜

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個贊

您可以獲得name單選按鈕的屬性,clicked根據(jù)這個屬性,我們將遍歷所有具有該名稱的單選按鈕和disable未選中的單選按鈕。


這是演示代碼:


$("input[type=radio]").click(function() {

  //getting name attribute if radio which is clicked

  var name = $(this).attr("name");

  console.log(name)

  //loop only through those radio where name is same

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

    //if not selected

    if ($(this).is(":not(:checked)")) {

      // add disable

      $(this).attr('disabled', 'disabled');

    }

  });


});

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

<input id="question_radio" type="radio" name="ans" value="<?php echo $result['id']; ?>" /> A

<input id="question_radio" type="radio" name="ans" value="<?php echo $result['id']; ?>" />B

<input id="question_radio" type="radio" name="ans" value="<?php echo $result['id']; ?>" />C

<br>

<input id="question_radio" type="radio" name="ans1" value="<?php echo $result['id']; ?>" />A

<input id="question_radio" type="radio" name="ans1" value="<?php echo $result['id']; ?>" /> B


<input id="question_radio" type="radio" name="ans1" value="<?php echo $result['id']; ?>" />C


查看完整回答
反對 回復(fù) 2023-05-12
?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個贊

這是純 Javascript 的實(shí)現(xiàn)


document.querySelectorAll("input[type=radio]").forEach(function (el) {

  el.addEventListener('click', function () {

    //getting name attribute if radio which is clicked

    var name = el.getAttribute('name');

    //loop only through those radio where name is same.

    document.querySelectorAll('input[name="' + name + '"]').forEach(function (el) {

      if (el.matches(":not(:checked)")) {

        el.setAttribute('disabled', 'disabled');

      }

    });

  });

});


查看完整回答
反對 回復(fù) 2023-05-12
  • 2 回答
  • 0 關(guān)注
  • 152 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號