删除jquery上的内容

时间:2013-11-05 08:28:23

标签: javascript jquery

你好我有点新的做javascript和jquery请帮我解决我的问题。我真的很感激。谢谢!

在第7-8页,如何删除“新游戏”按钮上的“已禁用” 使用jquery?

这是index.html:

 <!DOCTYPE>
<html>
<head>
    <link href="assets/css/blackjack.css" type="text/css" media="screen" rel="stylesheet">
    <script src="assets/js/Modernizr.js"></script>
    <script src="assets/js/jquery.js"></script>
    <script src="assets/js/Mustache.js"></script>
    <script src="assets/js/blackjack.js"></script>

</head>

<body>

    <div class="wrapper">

    <img src="assets/images/rocket-u-logo-large.png">
    <h1>Blackjack</h1>

    <p>Hi, thanks for stopping by our blackjack table. Pull up a chair and let's play...</p>

        <div id="card-table">

            <h2>Dealer</h2>

            <div id="dealer-hand"></div>

            <div id="status"></div>

            <div id="player-hand"></div>

            <h2>Player</h2>

                <div id="player-options">
                    <button class="bj" id="new-game" disabled>New Game</button>
                    <button class="bj" id="hit">Hit</button>
                    <button class="bj" id="stand">Stand</button>

                </div>

        </div>




    </div>


</body>
</html>

这是js:

$('#bj').click(function () {
    $('#hit').show();
    $('#stand').show();
});


function initGame() {

    var initErrors = [];
    var errorMessage;

    // Test if browser supports local storage
    if (Modernizr.localstorage) {
        // console.log("Local storage is supported.");
    } else {
        var errorStatus = "Local storage is not available"
        // console.log(errorStatus);
        initErrors.push(errorStatus);
    }

    // Test if browser supports mustache.js
    var mustacheScript = $('script[src*="js/Mustache.js"]').length; 
    if (mustacheScript != 0) {
        // console.log("Mustache loaded!");
    } else {
        var errorStatus2 = "Mustache not loaded."
        // console.log(errorStatus2);
        initErrors.push(errorStatus2);
    }



        function displayErrorMessage() {
        // Test if initErrors array has any errors
            if (initErrors.length != 0) {
                    if (errorStatus2 === undefined) {
                        errorStatus2 = "";
                        } else if (errorStatus === undefined) {
                                   errorStatus = "";
                    } 
            var errorMessage = "Houston, we have a problem (" + errorStatus + ', ' + errorStatus2 + ").";
            // console.log(errorMessage);
            $('#status').append("<p>" + errorMessage + "</p>");
            } else {
            var successMessage = "Ready to play? Click 'New Game' to start...";
            $('#status').append("<p>" + successMessage + "</p>");
            // console.log(successMessage);
            }

        }

        displayErrorMessage();


    //Test 'boolean' return values
    if (initErrors.length != 0) {
        return false;
        $('#new_game').attr("disabled", "disabled");
        } else {
        return true;
        $('#new_game').removeAttr("disabled");
    }


}   


console.log(initGame());

$(document).ready(function () {

    initGame();

});

4 个答案:

答案 0 :(得分:2)

您自己编写了代码。但它低于返回声明,这将使其可以访问。

带上下面的退货声明

$('#new_game').removeAttr("disabled");

它应该有用。

答案 1 :(得分:0)

$('#new-game').removeAttr('disabled');

看起来你的JS代码有错误:在HTML <button class="bj" id="new-game"中,但在JS $('#new_game').removeAttr("disabled");中。你在id。中使用下划线而不是' - '。

答案 2 :(得分:0)

你可以试试这个:

$('#new_game').prop('disabled',false);

答案 3 :(得分:0)

您可以使用下面列出的任何人

$('#new_game').attr("disabled", false);

OR

$("#new_game").removeAttr("disabled");

OR

$("#new_game").prop("disabled",false);