Home  >  Q&A  >  body text

When writing HTML to connect JavaScript files on Dreamweaver, the JavaScript code does not work. Please help! ?

I have just started learning JavaScript recently, and the tool I use is Adobe Dreamweaver CC 2017. After I finished writing the HTML file, I wanted to link to a JavaScript file, but the JavaScript file did not work. I don't know whether it's a problem with the software or something wrong with my code. After checking several times, there should be no path to link the JavaScript file, which can be seen in the picture.
My HTML code and JavaScript code are as follows:

HTML:

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Webville Tunes</title>
    <script src="../js/playlist.js"></script>
    <link rel="stylesheet" href="../css/playlist.css">
</head>
    
<body>
    <form type="text" id="songTextinput" size="40" placeholder="Song name">
        <input type="text" id="songTextInput" size="40" placeholder="Song name">
        <input type="button" id="addButton" value="Add Song">
    </form>
    <ul id="palylist">
        
    </ul>
</body>
</html>

JavaScript:

window.onload=init;
function init(){
    "use strict";
    var button=document.getElementById("addButton");
    button.onclick=handleButtonClick;
    
}

function handleButtonClick(){
    "use strict";
    alert("Button was clicked!");
}

I hope all the seniors will give me some advice, I’m very grateful!

漂亮男人漂亮男人2688 days ago1238

reply all(7)I'll reply

  • 学习ing

    学习ing2017-06-12 09:34:13

    Thanks for the invitation. What I want to know is whether your js file is useful or not. To check whether the js is loaded correctly, open firebug and check whether the js you are looking for is loaded correctly. If it is not loaded correctly, 404 will be reported. If It is indeed loaded, then debug this js to see if there is any problem. The js code you wrote should work if you put it directly into the page. If it doesn't work, there may be something wrong with the loading path.

    reply
    0
  • 滿天的星座

    滿天的星座2017-06-12 09:34:13

    First of all, give up Dreamweaver. Secondly, choose webstrom, sublimeText or whatever.

    reply
    0
  • 扔个三星炸死你

    扔个三星炸死你2017-06-12 09:34:13

    Please don’t write it like this. Just remove window.onload, put the script reference at the end of the body and call init directly. .

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-12 09:34:13

    There is no problem if the js part is added to the webpage, then you have to check to confirm

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-06-12 09:34:13

    It can be run through, and the writing is no problem

    reply
    0
  • 大家讲道理

    大家讲道理2017-06-12 09:34:13

    You put the introduced connection after the ul tag.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-12 09:34:13

    What compiler are you using?

    reply
    0
  • Cancelreply