【发布时间】:2020-06-06 14:00:54
【问题描述】:
我正在尝试编写一个简单的网页,其中一个段落中的文本被两个可能的段落之一替换,具体取决于单击了哪个按钮。当我单击任一按钮时,什么都没有发生。我试过移动代码,但这似乎不起作用。 这是整个文档,已编辑以保留不必要的细节
var mypar = document.getElementById("default");
document.getElementById("one").onclick = "Story1()"
document.getElementById("two").onclick = "Story2()"
function Story1(){
mypar.innerHTML = "long paragraph";
}
function Story2(){
mypar.innerHTML = "long paragraph";
}
body {
background-color: blue;
}
.button{
border-radius: 8px;
display: inline-block;
text-align: center;
background-color: #4CAF50;
padding: 15px 32px;
font-size: 32px;
}
h1 {
text-align: center;
color: yellow;
text-decoration: underline;
text-shadow: 2px 2px;
}
p {
padding-right: 50px;
padding-left:250px;
text-align: justify;
color: white;
font-style: italic;
font-weight: bold;
}
<h1>
<img src="people.jpg" alt= "onetwo" >
<br>
<button class="button" id = "one"> one </button>
<button class="button" id = "two"> two</button>
<br>
Heading </h1>
<p id = "p1">
long paragraph.</p>
<p id ="default">
</p>
<p id = "end">
written here
</p>
【问题讨论】:
标签: javascript html innerhtml