javascript - 无法从 Sublime Text 中的 html 访问 javascript 代码

标签 javascript jquery html

对于在线类(class),我必须制作一个使用 jQuery 和 JavaScript 的网页。我正在添加 JavaScript 代码,以便当我单击网页上带有文本“START”的按钮时,它应该消失,但我的网页却没有这样做。

HTML 代码:

<head>
    <link rel = 'stylesheet' type = 'text/css' href = 'memory_game.css'>
    <script src="C:\Users\Fabian\Documents\sublime\jquery-3.2.1.min"></script>
    <script type="text/javascript" src="memory_game.js"></script>
    <title>Concentration - Memory Game </title>

    <div class = headings>
        <h1>CONCENTRATION </h1>
        <h2>The shnazzy, feature-packed memory game! </h2>
    </div>

</head>

<body>

    <div class = 'rules'>
        <p>RULES: </p>
            <ol> 
                <li>The game consists of 16 cards on a 4 by 4 grid </li>
                <li>Initially, the cards will be faced up for a short period of time and, and will consist of 8 pairs, each with both cards having the same symbol </li>
                <li>Once these cards are faced back down, your objective is to try and remember which cards contained matching symbols</li>
                <li>Once you click one card, guess which one is paired with the card you just clicked, and if you get it correct, your score goes up by 1 </li>
                <li>If you guess a pair incorrectly, the two cards you click will be faced back down </li>
                <li>When you find all matching pairs, you win, and you get the option to play again </li>
                <li>Your performance rating at the end of the game will be a star rating of 1 to 3, which will be based on how many incorrect guesses you make, and how long it takes for you to win the game, for a timer will be shown during the game </li>
            </ol>
    </div>

    <div class = 'grid'> 
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>
        <img src = 'https://balancebest.co.uk/33349-home_default/flutter-fetti-orange-block-2.jpg' alt = 'block'>

    </div>

    <div id = 'startButton'>
        <button>START</button>
    </div>

    <div id = 'reStartButton'>
        <button>RESTART</button>
    </div>

    <div id = 'score'>
        <p>SCORE: </p>
    </div>

</body>

JavaScript 代码:

$('#startButton').click(function() {
    $('##startButton').hide();
});

无需担心 css,因为只需担心 JavaScript 和 html。

如果您有任何建议,请回复此问题。

谢谢

最佳答案

##startButton 没有选择任何元素,所以 JS 代码应该是

$('#startButton').click(function() {
    $('#startButton').hide();
});

关于javascript - 无法从 Sublime Text 中的 html 访问 javascript 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45967853/

相关文章:

javascript - 如何使用 javascript 在单个页面中添加多个日历

javascript - 无序列表中项目的交替背景颜色

javascript - 无法在我的 HTML 上查找 Assets ,从 Go 网络服务器提供服务

javascript - 使用ajax从同一文件中的javascript调用PHP函数

javascript - 如何实现和使用 eyecon 的 bootstrap-datepicker?

javascript - JQuery.parseJSON 不适用于字符串

html - 水平滚动容器网页

html - div 的内容移动到其他 div 下方

javascript - Select2限制标签数量

javascript - 根据属性值删除重复项