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

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

當(dāng)我計算選中的框時,它會加上一個框

當(dāng)我計算選中的框時,它會加上一個框

哆啦的時光機 2023-04-14 17:07:21
我的網(wǎng)絡(luò)應(yīng)用程序是關(guān)于體育比賽的預(yù)測。我的頁面顯示了所有比賽以及您可以從一場比賽的每個結(jié)果中獲得的分?jǐn)?shù)(馬德里 = 12 分 VS 巴塞羅那 = 15 分)。因此,用戶在匹配項中選中一個框并為他選擇正確的結(jié)果。我希望每次用戶選中一個框時,向他顯示他選中的框數(shù)。這是我的 Javascript 來計算選中的框:    const updateCount = function() {      var x = document.querySelectorAll(".square:checked").length;      document.querySelector(".plus").innerHTML = x;    };這是將顯示選中框數(shù)量的 HTML<div class=" d-flex pt-2">            <h3 class="typos">Matchs pronostiqués</h3>            <h3 class="typos pts" style="font-weight: bold; padding-left: 5px;"><%= current_user.forecasts.where(confirmed: true, season_id: Season.last.id).count %>/50</h3>            <span class="plus"></span>          </div>這是我的 Javascript,以便了解用戶預(yù)測的游戲以及他選擇的結(jié)果:const selectOutcome = () => {  const selects = document.querySelectorAll(".square");  selects.forEach((outcome)=>{    outcome.addEventListener("click",(event) => {  $('input[type="checkbox"]').on('change', function() {   $(this).siblings('input[type="checkbox"]').not(this).prop('checked', false);});      const result = event.currentTarget.dataset.outcome;      console.log(result);      const id = event.currentTarget.parentNode.dataset.id;      console.log(id);      const box = event.currentTarget.checked;      console.log(box);      const url = 'store_outcome?result='+result+'&match='+id+'&box='+box      fetch(url)        .then(response => response.json())        .then((data) => {      console.log(data);      });    });  });}const validePanier = () => {  const panier = document.getElementById('panier');  panier.addEventListener("click", (event) =>{    console.log("click")    const player = document.getElementById('season_player').value;    fetch('confirm_pending?player='+player)    .then(response => response.json())    .then((data) => {    console.log(data);    });  })}有一個數(shù)據(jù)ID。目的是當(dāng)用戶選中一個框時,我可以獲得匹配的 ID,以便為正確的游戲創(chuàng)建正確的預(yù)測。
查看完整描述

1 回答

?
梵蒂岡之花

TA貢獻(xiàn)1900條經(jīng)驗 獲得超5個贊

我會委托而不是使用內(nèi)聯(lián)事件處理程序


在這里我計算復(fù)選框 - 為什么你不想要選中的 RADIO 的值?


注意我把所有的火柴都包裹在<div id="matches">...</div>


document.getElementById("matches").addEventListener("change", function(e) {

  const tgt = e.target;

  if (tgt.classList.contains("square")) {

    const parent = tgt.closest(".displaysquares");

    var x = parent.querySelectorAll(".square:checked").length;

    document.querySelector(".plus").innerHTML += parent.dataset.id + ": " + x +"<br/>" ;

  }

})

<span class="plus"></span>

<div id="matches">

  <div class="d-flex justify-content-center mb-2 mt-2">

    <h4 class="typopo">League 1</h4>

  </div>

  <div class="d-flex justify-content-center mb-2 mt-2">

    <h3 class="tit">

      Some date

    </h3>

    <h3 class="typopo pl-2">-</h3>

    <h3 class="typopo pl-2">Some string</h3>

  </div>

  <div class="d-flex flex-row justify-content-around mb-4 mt-4" data-id="MATCH 1">

    <div class="d-flex flex-column align-items-center col-4">

      <div class="row">

        <h3 class="typopo">TEAM LOGO </h3>

      </div>

      <div class="row text-align-center">

        <h3 class="tit">Some other team string</h3>

      </div>

    </div>

    <div class="d-flex flex-column justify-content-center">

      <p class="typopo text-center">VS</p>

      <div class="d-flex flex-row align-items-center col-4">

        <div class="displaysquares" data-id="MATCH 1">

          <input type="checkbox" class="square" data-outcome="1">

          <input type="checkbox" class="square" data-outcome="NULL">

          <input type="checkbox" class="square" data-outcome="2">

        </div>

      </div>

    </div>

  </div>


  <div class="d-flex justify-content-center mb-2 mt-2">

    <h4 class="typopo">League 2</h4>

  </div>

  <div class="d-flex justify-content-center mb-2 mt-2">

    <h3 class="tit">

      Some date

    </h3>

    <h3 class="typopo pl-2">-</h3>

    <h3 class="typopo pl-2">Some string</h3>

  </div>

  <div class="d-flex flex-row justify-content-around mb-4 mt-4" data-id="MATCH 2">

    <div class="d-flex flex-column align-items-center col-4">

      <div class="row">

        <h3 class="typopo">TEAM LOGO </h3>

      </div>

      <div class="row text-align-center">

        <h3 class="tit">Some other team string</h3>

      </div>

    </div>

    <div class="d-flex flex-column justify-content-center">

      <p class="typopo text-center">VS</p>

      <div class="d-flex flex-row align-items-center col-4">

        <div class="displaysquares" data-id="MATCH 2">

          <input type="checkbox" class="square" data-outcome="1">

          <input type="checkbox" class="square" data-outcome="NULL">

          <input type="checkbox" class="square" data-outcome="2">

        </div>

      </div>

    </div>

  </div>

</div>

改用收音機


const matches = document.getElementById("matches")

matches.addEventListener("change", function(e) {

  const tgt = e.target;

  if (tgt.classList.contains("square")) {

    var x = [...matches.querySelectorAll(".square:checked")].map(chk => chk.closest(".displaysquares").dataset.id + ": "+chk.dataset.outcome)

    document.querySelector(".plus").innerHTML = x.join("<br/>");

  }

})

<span class="plus"></span>

<div id="matches">

  <div class="d-flex justify-content-center mb-2 mt-2">

    <h4 class="typopo">League 1</h4>

  </div>

  <div class="d-flex justify-content-center mb-2 mt-2">

    <h3 class="tit">

      Some date

    </h3>

    <h3 class="typopo pl-2">-</h3>

    <h3 class="typopo pl-2">Some string</h3>

  </div>

  <div class="d-flex flex-row justify-content-around mb-4 mt-4" data-id="MATCH 1">

    <div class="d-flex flex-column align-items-center col-4">

      <div class="row">

        <h3 class="typopo">TEAM LOGO </h3>

      </div>

      <div class="row text-align-center">

        <h3 class="tit">Some other team string</h3>

      </div>

    </div>

    <div class="d-flex flex-column justify-content-center">

      <p class="typopo text-center">VS</p>

      <div class="d-flex flex-row align-items-center col-4">

        <div class="displaysquares" data-id="MATCH 1">

          <input type="radio" name="outcome1" class="square" data-outcome="1">

          <input type="radio" name="outcome1" class="square" data-outcome="NULL">

          <input type="radio" name="outcome1" class="square" data-outcome="2">

        </div>

      </div>

    </div>

  </div>


  <div class="d-flex justify-content-center mb-2 mt-2">

    <h4 class="typopo">League 2</h4>

  </div>

  <div class="d-flex justify-content-center mb-2 mt-2">

    <h3 class="tit">

      Some date

    </h3>

    <h3 class="typopo pl-2">-</h3>

    <h3 class="typopo pl-2">Some string</h3>

  </div>

  <div class="d-flex flex-row justify-content-around mb-4 mt-4" data-id="MATCH 2">

    <div class="d-flex flex-column align-items-center col-4">

      <div class="row">

        <h3 class="typopo">TEAM LOGO </h3>

      </div>

      <div class="row text-align-center">

        <h3 class="tit">Some other team string</h3>

      </div>

    </div>

    <div class="d-flex flex-column justify-content-center">

      <p class="typopo text-center">VS</p>

      <div class="d-flex flex-row align-items-center col-4">

        <div class="displaysquares" data-id="MATCH 2">

          <input type="radio" name="outcome2" class="square" data-outcome="1">

          <input type="radio" name="outcome2" class="square" data-outcome="NULL">

          <input type="radio" name="outcome2" class="square" data-outcome="2">

        </div>

      </div>

    </div>

  </div>

</div>


查看完整回答
反對 回復(fù) 2023-04-14
  • 1 回答
  • 0 關(guān)注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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