When writing HTML to connect JavaScript files on Dreamweaver, the JavaScript code does not work. Please help! ?
漂亮男人
漂亮男人 2017-06-12 09:32:13
0
7
1261

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!

漂亮男人
漂亮男人

reply all(7)
学习ing

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.

滿天的星座

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

扔个三星炸死你

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. .

给我你的怀抱

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

仅有的幸福

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

大家讲道理

You put the introduced connection after the ul tag.

伊谢尔伦

What compiler are you using?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!