简体   繁体   中英

HTML button not linking to JavaScript function

Hey guys just having an issue with my HTML button not actually running my javascript function when clicked on.

The HTML:

<html>
<head>
<meta charset="utf-8">
<title>PROJECT</title>
<script language="javascript" src="Hangman.js"></script> 
</head>
<body>
  <input id = "Begin" type = "button" value = "Play">       
</body>
</html>

And here's the JS:

function start () 
    {
     document.getElementById("Begin").addEventListener("click",logic,false);
    }

function logic () 
    {
        document.writeln("yo");
    }

 window.addEventListener("load", start, false);

Sorry if this is an amateur question, it just so happens I'm an amateur. Thanks you guys in advance!

check this jsfiddle it is fixed

function start () 
    {
     document.getElementById("Begin").addEventListener("click",logic,false);
    }

function logic () 
    {
       alert();
    }

window.onLoad=start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM