【问题标题】:How can i get a pair of buttons to appear in Javascript?如何让一对按钮出现在 Javascript 中?
【发布时间】:2014-03-22 04:04:15
【问题描述】:

所以我有这个课堂作业,我一直在努力想办法让两个我故意隐藏的buttons 在点击开始button 后出现。点击开始按钮,然后点击3张卡片后,会出现Hold and Draw按钮

对不起,如果这含糊不清,我是 JavaScript 的新手,并且对 StackOverflow 非常陌生:

JavaScript:

function onCardClick( cardNum ) 
    {
        if ( cardToggle[cardNum-1] ) // Is the card cycling?
        {
            console.log("Card index "+CardsShown[cardNum-1]+" clicked.");
            console.log("Before spl: "+indexArray);
            indexArray.splice(indexArray.indexOf(CardsShown[cardNum-1]), 1);
            console.log("After spl: "+indexArray);
        }
        else if ( CardsShown[cardNum-1] != -1 )
        {
            indexArray.push(CardsShown[cardNum-1]);
            indexArray.sort(sortNumber);
            console.log("After push: "+indexArray);
        }
        cardToggle[cardNum-1] = !cardToggle[cardNum-1];
    }

    function showButton 
    {
        if( ) {
        document.getElementById("buttonVisibility").style.visibility="visible";
        }
    }

    function sortNumber(a,b)
    {
        return a - b;
    }

HTML:

</head>
<body>
<h1>Welcome To The game</h1>
    <div class="stage">
        <ul id="card">
            <li id="card1" onclick="onCardClick(1)"><a></a></li>
            <li id="card2" onclick="onCardClick(2)"><a></a></li>
            <li id="card3" onclick="onCardClick(3)"><a></a></li>
            <li id="card4" onclick="onCardClick(4)"><a></a></li>
            <li id="card5" onclick="onCardClick(5)"><a></a></li>
            <button onclick="onCardClick(1); onCardClick(2); onCardClick(3); onCardClick(4); onCardClick(5);">Start</button>
            <button id="buttonVisibility">Hold</button>
            <button id="buttonVisibility">Draw</button>
        </ul>
    </div>
</body>

【问题讨论】:

    标签: javascript html function button


    【解决方案1】:

    您的代码中有很多错误,例如,

    () 没有括号 showButton 函数

    function showButton (){
    //------------------^ should add parenthesis
    

    ifshowButton() 中没有表达式,例如。

    if( /here should be some expression/ ) {
    

    cardToggle 未在上述代码中的任何地方定义。

    先把这些都改正,看看结果如何。

    【讨论】:

    • 感谢您指出这一点。我可以肯定地调试程序,但我只需要一些关于如何使两个按钮出现的指示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 2012-03-09
    • 2018-10-07
    • 1970-01-01
    • 2021-11-13
    相关资源
    最近更新 更多