一键显示/隐藏功能(hide_btn)



我必须为考试编写一个网络应用程序(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_btn时,所有内容都会消失,并且将显示此"--"。单击有效,但我想隐藏从数组中获得的数字,例如。"32">

提前非常感谢

$("*").html("--"); // This overrides all html inside body and prints "--".

您可以将其替换为

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

最新更新