我遇到了JavaScript问题。 我想要发生的事情:单击“修改HTML内容”后,将“原始内容”h1更改为“新内容”,再次单击时,“新内容”更改为“原始内容”。当点击“删除HTML内容”按钮时,h1标题消失,再次单击时,空白更改为“原始内容”。相反,没有任何反应。 h1标题保持不变。有人可以帮忙吗?使用按钮更改标题
HTML:
<html>
<head>
<title>Content Change</title>
<script type="text/javascript" src="contentchange.js"></script>
</head>
<body>
<h1 id="heading"><b>The Original Content</b></h1>
<br/>
<button type="button" onclick="change()" id="button_one">Modify HTML content</button>
<button type="button" onclick="change_2()" id="button_two">Delete HTML content</button>
</body>
</html>
的JavaScript:
//Code for the Modify HTML content button
function change()
{
var elem = document.getElementById("button_one");
if (h1.value=="The Original Content")
{h1.value = "The New Content";}
else
{h1.value = "The Original Content";}
}
//Code for the Delete HTML content button
function change_2()
{
var elemtwo = document.getElementById("button_two");
if (h1.value=="The Original Content" || "The New Content")
{h1.value = "";}
else
{h1.value="The Original Content"}
}
变量'h1'定义在哪里? – Regent 2014-09-12 21:21:08
当定义了h1时(参见上面的Regent)将if(h1.value ==“原始内容”||“新内容”)行改为if(h1.value ==“The Original Content “|| h1.value ==”新内容“)' – 2014-09-12 21:25:43