非常简单的Javascript难倒 [英] Stumped by extremely simply Javascript
本文介绍了非常简单的Javascript难倒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在近3年内没有直接用Javascript编码,而我最近又回到了它。话虽这么说,我不能为我的生活弄清楚为什么这不起作用。
I haven't coded in Javascript directly in almost 3 years and I'm just recently jumping back into it. That being said, I can not for the life of me figure out why this isn't working.
<!DOCTYPE html>
<html>
<head><title>Hello</title><script>
function changeH1Text()
{
document.getElementById("H1").innerHTML = "I've been changed";
}
</script></head>
<body>
<h1 id="H1" önload="changeH1Text()">Welcome to Javascript</h1>
<button type="button" onclick="document.getElementID("body").Text = 'The button changed me';">Click Me!</button>
</body>
</html>
推荐答案
<html>
<head>
<title>Hello</title>
<script>
function changeH1Text()
{
document.getElementById("H1").innerHTML = "I've been changed";
}
</script>
</head>
<body id="body" önload="changeH1Text();">
<h1 id="H1">Welcome to Javascript</h1>
<button type="button" önclick="document.getElementById('body').innerHTML = 'The button changed me';">Click Me!</button>
</body>
</html>
我建议你使用FireBug。它非常方便的插件;)
I am recommending you to use FireBug. Its really handy plugin ;)
问题
如果你在FireFox中检查FireBug的控制台选项卡,你会看到以下问题那里。
Problem
If you check the console tab of FireBug in FireFox, you can see the following issue there.
Quote:
语法错误:语法错误
document.getElementID(
ThirdPage.aspx(第1行,第22栏)
SyntaxError: syntax error
document.getElementID(
ThirdPage.aspx (line 1, col 22)
它明确提到错误在 document.getElementID(
。
这里有两个问题。
- 那是
文件。 getElementByID
不是document.getElementID
。 - 你的代码中没有元素,它有一个ID作为正文,它更像是一个标记。
这篇关于非常简单的Javascript难倒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文