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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

根據(jù)選中的收音機(jī)切換課程

根據(jù)選中的收音機(jī)切換課程

達(dá)令說(shuō) 2022-06-09 16:59:01
根據(jù)檢查哪個(gè)收音機(jī),我想切換兩個(gè)類“l(fā)eftChoice”和“rightChoice”不幸的是代碼不起作用。我試圖在沒(méi)有 jQuery 的情況下使用純 JS。也許有更簡(jiǎn)單的方法來(lái)獲得結(jié)果。var wrapper = document.getElementById('wrapper');var choices = document.getElementsByName("choices");var checkedChoice = "";wrapper.classList.remove("rightChoice");wrapper.classList.add("leftChoice");choices.onchange(function() {      for (var i = 0, length = choices.length; i < length; i++) {        if (choices[i].checked) {            checkedChoice = choices[i].value;            break;        }    }     if(checkedChoice == "one"){           wrapper.classList.remove("rightChoice");        wrapper.classList.add("leftChoice");    }    else if(checkedChoice == "two"){        wrapper.classList.remove("leftChoice");        wrapper.classList.add("rightChoice");    }});https://jsfiddle.net/Lo6pzn1a/
查看完整描述

1 回答

?
素胚勾勒不出你

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊

修復(fù)了問(wèn)題。在純 JS 中,您必須分別在每個(gè)元素上添加事件監(jiān)聽(tīng)器。小提琴鏈接:https ://jsfiddle.net/561x90k4/


var wrapper = document.getElementById('wrapper');

var choices = document.getElementsByName("choices");

var checkedChoice = "";


wrapper.classList.remove("rightChoice");

wrapper.classList.add("leftChoice");


choices.forEach(item => item.addEventListener('change',(function() {  

    for (var i = 0, length = choices.length; i < length; i++) {

        if (choices[i].checked) {

            checkedChoice = choices[i].value;

            break;

        }

    } 

    if(checkedChoice == "one"){   

        wrapper.classList.remove("rightChoice");

        wrapper.classList.add("leftChoice");

    }

    else if(checkedChoice == "two"){

        wrapper.classList.remove("leftChoice");

        wrapper.classList.add("rightChoice");

    }

})));

.clearfix::before {

    content: "";

    display: table;

}

.clearfix::after {

    content: "";

    display: table;

    clear: both;

}


.choice {

  display: inline-block;

  position: relative;

  cursor: pointer;

  font-size: 25px;

  -webkit-user-select: none;

  -moz-user-select: none;

  -ms-user-select: none;

  user-select: none;

  width: 49%;

}


.choice input {

  position: absolute;

  opacity: 0;

  cursor: pointer;

}


.choice > .checkmark {

  position: relative;

  display: block;

  padding: 10px;

  background-color: #eee;

}



.choice:hover input ~ .checkmark {

  background-color: #ccc;

}



.choice input:checked ~ .checkmark {

  background-color: #2196F3;

}


label.choice,

.choice_arrow {

    float: left;

    width: 30%;

}


.choice_arrow {

    width: 20%;

    background: #f00;

    position: relative;

    height: 48px;

    border-radius: 30px;

    border: 1px solid #ccc;

}

.choice_arrow > .bullet {

    border-radius: 50%;

    width: 43px;

    height: 43px;

    position: absolute;

    background: #ff0;

    border: 1px solid #ccc;

    top: 1px;

}

.choice_arrow > .bullet > span {

    font-size: 30px;

    margin-top: 7px;

    margin-left: 7px;

}


#wrapper.leftChoice .choice_arrow .bullet { left: 2px; transform: rotate(0deg); }

#wrapper.rightChoice .choice_arrow .bullet  { right: 2px; transform: rotate(180deg); }

<div id="wrapper" class="clearfix">

  <label class="choice">

    <input type="radio" id="choice1" checked="checked" name="choices" value="one">

    <span class="checkmark">Choice 1</span>

  </label>

  <div class="choice_arrow">

    <div class="bullet">

      <span class="fa fa-chevron-left"></span>

    </div>

  </div>

  <label class="choice">

    <input type="radio" id="choice2" name="choices" value="two">

    <span class="checkmark">Choice 2</span>

  </label>

</div>


查看完整回答
反對(duì) 回復(fù) 2022-06-09
  • 1 回答
  • 0 關(guān)注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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