Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using Notepad++, and I know for sure that it works when linking different files to the main HTML file.Here is the HTML code I'm using:

    <link rel="stylesheet" type="style/css" href="adventure.css"></link>
    <script src="adventure.js"></script>
</head>
<body>
    <button onclick=log("testing")>Click Me</button>
    <div id="box">
        <div id="out"></div>
    </div>
</body>

And here is the JavaScript code:

function Gid(id) {
return getElementById(id);
}
function log(s) {
    Gid("out").innerHTML = s + "<br>" +
    Gid("out").innerHTML;
}

And the CSS for the divs

#box {
    width:500px;
    height:300px;
    border:5px solid black;
    overflow:auto;
}
#out {
    width:500px;
}

Please help me figure out why it's not working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
256 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to call function on onclick event as :

onclick="log('testing')"

and you have to also use

return document.getElementById(id);

in Gid function

that's it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...