代码之家  ›  专栏  ›  技术社区  ›  Paddy

在一个按钮中显示/隐藏功能(hide\u btn)

  •  0
  • Paddy  · 技术社区  · 7 年前

    我必须为考试编写一个web应用程序(M·xle),我完全是个初学者。 希望s.o.能帮助我。

    指数html(按钮):

    <div id="buttons_container" class="container">
                <div class="row">
                    <br>
                    <button type="button" id="shuffle_btn" class="btn btn-primary">shuffle</button>
    
                    <button type="button" id="hide_btn" class="btn btn-success">hide / show</button>
                </div>
            </div>
    

    作用js公司:

    function test_shuffle () {
    
    var arr = ["11",
        "21","22",
        "31","32","33","34","35","36",
        "41","42","43","44","45","46",
        "51","52","53","54","55","56",
        "61","62","63","64","65","66"];
    
    var max_index = arr.length -1;
    
    var zufall = Math.floor(Math.random() * max_index) + 1 ;
    
    var final = arr [zufall];
    
    $('#ausgabe_shuffle').html(final);
    
    }
    
    function test_hide () {
    
    $("hide_btn").click(function(){
    $("--").hide();
    });
    }
    

    事件js公司:

    $(document).ready(function() {
    
    $('body').on('click', '#shuffle_btn', function (e) {
    
        test_shuffle ();
    
    });
    
    $('body').on('click', '#hide_btn', function (e) {
        $("*").html("--");
    
        test_hide ();
    
    });
    });
    

    当我现在单击hide\u btn时,所有内容都会消失,并显示“-”。点击有效,但我想隐藏从数组中获得的数字,例如“32”

    提前非常感谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Praveen Alluri    7 年前
    $("*").html("--"); // This overrides all html inside body and prints "--".
    

    您可以将其替换为

    $("#ausgabe_shuffle").toggle(); // This will show or hide your values printed inside #ausgabe_shuffle tag.