Javascript无法使用HTML外部链接 [英] Javascript not working with HTML external link
本文介绍了Javascript无法使用HTML外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Notepad ++,我确信它可以在将不同文件链接到主HTML文件时起作用。这是我正在使用的HTML代码:
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>
这是JavaScript代码:
And here is the JavaScript code:
function Gid(id) {
return getElementById(id);
}
function log(s) {
Gid("out").innerHTML = s + "<br>" +
Gid("out").innerHTML;
}
div的CSS
#box {
width:500px;
height:300px;
border:5px solid black;
overflow:auto;
}
#out {
width:500px;
}
请帮我弄清楚它为什么不起作用。
Please help me figure out why it's not working.
推荐答案
您必须在onclick事件上调用函数:
You have to call function on onclick event as :
onclick =log('testing')
onclick="log('testing')"
您也必须使用
and you have to also use
在Gid函数中返回document.getElementById(id);
return document.getElementById(id);
就是这样。
这篇关于Javascript无法使用HTML外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文