我有一个页面,其中包含<input>
和<span>
。如何通过用户输入更改文本?
我不知道该怎么做,用户在输入中写入的文本将显示为跨度。
的代码(即不顺利):
HTML:
<h1>Lets talk with SpongBob!</h1>
<span>Say "hello":</span>
<form name="frm"><input name="question" type="text"><input id="submit" type="submit" value="Submit"></form>
<div id="igool"><span id="talk"></span></div>
<div id="Triangle"></div>
<img src="http://static.tumblr.com/f1bbfdf0fd794b1cf8d243d65644be01/i0ldeup/bURmj2ccf/tumblr_static_spongebob.jpg"/>
CSS:
body {
font-family: "Comic Sans MS", cursive, sans-serif;
}
h1 {
text-align: center;
}
img {
width: 300px;
margin-left: 20%;
}
input {
position: absolute;
width: 10%;
margin-left: 45%;
border: 2px solid black;
border-radius: 4px;
background-color: lightgray;
}
#submit {
margin-left: 57%;
width: 5%;
}
span {
position: absolute;
margin-left: 37%;
}
#Triangle {
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 30px solid lightgray;
margin-top: -0.5%;
margin-left: 41%;
}
#igool {
width: 120px;
height: 100px;
background-color: lightgray;
border-radius: 100%;
margin-left: 38%;
margin-top: 8%;
}
#talk {
margin-left: 2%;
margin-top: 3%;
}
的Javascript
if (document.forms['frm'].question.value == "hello") {
document.getElementById("talk").innerHTML="Hello you to!";
}
else {
document.getElementById("talk").innerHTML="WhatEver...";
}
什么时候你想让它工作?当你点击提交? – lshettyl