我遇到了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