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

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

單選按鈕值傳輸

單選按鈕值傳輸

藍山帝景 2021-08-20 14:59:35
指向我編碼的其他頁面的單選按鈕的不同鏈接應該在用戶選擇一個單選按鈕并單擊繼續(xù)后出現(xiàn)。所選單選按鈕的鏈接不應立即打開,因為用戶必須先在該頁面上輸入其他信息。我已經(jīng)在單選按鈕代碼中包含了鏈接,但它們在選擇后立即打開。所以我從我的示例代碼中刪除了它們。還嘗試使用 JavaScript 獲取單選按鈕的值,但我不知道如何傳輸它。<!-- begin radio buttons --><div class="panel-variation">    <div class="panel-body"></div>        <div class="radio-buttons-variation">            <ul class="radio-buttons-left">                <li>                    <input type="radio" name="selection" id="A" value="Hanna">                    <label>Hanna</label>                </li>                <li>                    <input type="radio" name="selection" id="B" value="Bryan">                    <label>Bryan</label>                </li>                <li>                    <input type="radio" name="selection" id="C" value="Alex">                    <label>Alex</label>                </li>            </ul>            <ul class="radio-buttons-right">                <li>                    <input type="radio" name="selection" id="D" value="Gabby">                    <label>Gabby</label>                </li>                <li>                    <input type="radio" name="selection" id="E" value="Dan">                    <label>Dan</label>                </li>                <li>                    <input type="radio" name="selection" id="F" value="Ryan">                     <label>Ryan</label>                </li>            </ul>        </div>    </div></div><!-- end radio buttons --><!-- begin continue button --><div class="buttons">    <a href="#" class="r7-button">continue</a></div><!-- end continue button -->// getting the selected radio button value function select () {    document.querySelector('input[name="selection"]:checked').value;}//transferring value to continue button?我想需要一些 JavaScript,它將單選按鈕的選擇作為值傳輸?shù)脚c繼續(xù)按鈕相關的另一個函數(shù)。因此,單擊繼續(xù)按鈕后,單選按鈕鏈接將打開。
查看完整描述

2 回答

?
飲歌長嘯

TA貢獻1951條經(jīng)驗 獲得超3個贊

首先,您需要將一個單擊事件偵聽器附加到您的繼續(xù)按鈕。在它的回調(diào)函數(shù)中,您可以檢查單選按鈕。


為此,您可以使用document.getElementsByName("selection"),它返回一個NodeList - 本質(zhì)上是一個數(shù)組 - 所有具有selection名稱的元素?,F(xiàn)在簡單地使用 for 循環(huán)遍歷數(shù)組,看看是否有一個.checked屬性為 true的元素并采取相應的行動。


下面是一個例子:


function check() {

var found=false;

  var inputElements = document.getElementsByName("selection");

  for (var a = 0; a < inputElements.length; a++) {

    if (inputElements[a].checked) {

      console.log(inputElements[a].value + " is checked!");

      found=true;

      // continue!

    }

  }

  if(!found)

  {

  console.log("nothing selected!");

  }

}

document.getElementsByClassName("r7-button")[0].addEventListener("click", check);

<!-- begin radio buttons -->

<div class="panel-variation">

  <div class="panel-body"></div>

  <div class="radio-buttons-variation">

    <ul class="radio-buttons-left">

      <li>

        <input type="radio" name="selection" id="A" value="Hanna">

        <label>Hanna</label>

      </li>

      <li>

        <input type="radio" name="selection" id="B" value="Bryan">

        <label>Bryan</label>

      </li>

      <li>

        <input type="radio" name="selection" id="C" value="Alex">

        <label>Alex</label>

      </li>

    </ul>


    <ul class="radio-buttons-right">

      <li>

        <input type="radio" name="selection" id="D" value="Gabby">

        <label>Gabby</label>

      </li>

      <li>

        <input type="radio" name="selection" id="E" value="Dan">

        <label>Dan</label>

      </li>

      <li>

        <input type="radio" name="selection" id="F" value="Ryan">

        <label>Ryan</label>

      </li>

    </ul>

  </div>

</div>

<!-- end radio buttons -->


<!-- begin continue button -->

<div class="buttons">

  <a href="#" class="r7-button">continue</a>

</div>


查看完整回答
反對 回復 2021-08-20
?
森林海

TA貢獻2011條經(jīng)驗 獲得超2個贊

push()像這樣使用函數(shù):


var answers = [];


// getting the selected radio button value 

function select () {

    var answer = document.querySelector('input[name="selection"]:checked').value;

    answers.push(answer); //transferring value to continue button

}


// Index marks which question it was so answers[0] would be the first question and

 answers[1] would be the second

如果您需要更多幫助,請詢問我。


查看完整回答
反對 回復 2021-08-20
  • 2 回答
  • 0 關注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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