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

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

我怎樣才能通過使用 jQuery 單擊按鈕來獲得下一個問題

我怎樣才能通過使用 jQuery 單擊按鈕來獲得下一個問題

交互式愛情 2023-03-24 14:50:41
我想修改這個 jQuery 代碼,這樣當我按下“下一步”按鈕時,下一個問題應該出現,但不是通過單擊單選按鈕。<!DOCTYPE html>    <html>        <head>      <title>jQuery Get Selected Radio Button Value</title>      <style>        * {          background-color: wheat;          font-size: 40px;          align-self: center;        }            .big {          width: 20px;          height: 20px;        }            #title {          font-size: 50px;          text-align: center;          width: 100%;          color: tomato        }            div {          width: 100%;          display: block;          text-align: center;        }        #next{          float:right;          margin-right: 20%;          color:tomato          }      </style>      <script src="https://code.jquery.com/jquery-3.5.1.min.js"        integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>      <script>        $(document).ready(function () {          $('#game,#movie,#sport,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();              $('#hobbie input').on('change',function () {            var x = $('#game,#movie,#sport,#genre,#action,#game,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport  ').hide();            $('#' + $(this).val()).slideDown();          })          $('#movie input').change(function () {            $('#game,#sport,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();            $('#' + $(this).val()).show();          })              $('#game input').change(function () {            $('#movie,#sport,#genre,#action,#game#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();            $('#' + $(this).val()).show();          })              $('#sport input').change(function () {            $('#game,#movie,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();            $('#' + $(this).val()).show();          })
查看完整描述

1 回答

?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

我不明白你要求用戶進行多項操作(選擇選項并單擊按鈕),他只需在代碼中選擇任何選項即可獲得相應的選項。無論如何,您可以嘗試下面的代碼,通過單擊下一步按鈕獲得下一個問題。(這可能是硬編碼的例子:P)


<script>

        $(document).ready(function () {

            $('#game,#movie,#sport,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();

            

            $('#hobbie input').on('change',function () {

                var x = $('#game,#movie,#sport,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();

            })

            $('#movie input').change(function () {

                $('#game,#sport,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();

            })

            

            $('#game input').change(function () {

                $('#movie,#sport,#genre,#action,#game#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();

            })

            

            $('#sport input').change(function () {

                $('#game,#movie,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();

            })

            

          // for button position

          jQuery.fn.center = function () {

            this.css("position","absolute");

            this.css("top", ( $(window).height() - this.height() ) / 1.2+$(window).scrollTop() + "px");

            this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");

            return this;

          }

          $('#next').center();

          $("#next").on('click', function(){

            var hobbieselected = $('input[name=hobbie]:checked').val();

            var movieselected = $('input[name=movie]:checked').val();

            var gameselected = $('input[name=game]:checked').val();

            var sportselected = $('input[name=sport]:checked').val();

            

            if(hobbieselected == 'movie'){

                $('#game,#sport,#gta,#fpp,#action,#adventure,#scifi#historic,#indoor,#outdoor,#esport').hide();

                $('#movie').show();

            }

            else if(hobbieselected == 'game'){

                $('#movie,#sport,#gta,#fpp,#action,#adventure,#scifi#historic,#indoor,#outdoor,#esport').hide();

                $('#game').show();

            }

            else if(hobbieselected == 'sport'){

                $('#movie,#game,#gta,#fpp,#action,#adventure,#scifi#historic,#indoor,#outdoor,#esport').hide();

                $('#sport').show();

            }

            if(hobbieselected == 'movie' && movieselected == 'action'){

                $('#game,#sport,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();

                $('#action').show();

            }

            else if(hobbieselected == 'movie' && movieselected == 'adventure'){

                $('#sport,#action,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();

                $('#adventure').show();

            }

            else if(hobbieselected == 'movie' && movieselected == 'scifi'){

                $('#sport,#action,#adventure,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();

                $('#scifi').show();

            }

            if(hobbieselected == 'game' && gameselected == 'gta'){

                $('#sport,#adventure,#scifi,#action,#fpp,#historic,#indoor,#outdoor,#esport').hide();

                $('#gta').show();

            }

            else if(hobbieselected == 'game' && gameselected == 'fpp'){

                $('#movie,#sport,#genre,#action,#game#adventure,#scifi,#gta,#historic,#indoor,#outdoor,#esport').hide();

                $('#fpp').show();

            }

            else if(hobbieselected == 'game' && gameselected == 'historic'){

                $('#movie,#sport,#genre,#action,#game#adventure,#scifi,#gta,#fpp,#indoor,#outdoor,#esport').hide();

                $('#historic').show();

            }

            if(hobbieselected == 'sport' && sportselected == 'indoor'){

                $('#game,#adventure,#scifi,#gta,#fpp,#historic,#action,#outdoor,#esport').hide();

                $('#indoor').show();

            }

            else if(hobbieselected == 'sport' && sportselected == 'outdoor'){

                $('#game,#movie,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#esport').hide();

                $('#outdoor').show();

            }

            else if(hobbieselected == 'sport' && sportselected == 'esport'){

                $('#game,#movie,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor').hide();

                $('#esport').show();

            }

          });

      });

  </script>


查看完整回答
反對 回復 2023-03-24
  • 1 回答
  • 0 關注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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