0

I want to combine these two blocks in the script. I want it so that when you type river into the text box i can give a good job statement or post a link. I don't know what to use as the variable in the second statement. Which is the if statement.

var userInput.value=river;
if(userInput.value)=="river"){
document.write("hey");
}
<br/>
function changeText2(){
var userInput=document.getElementById('userInput').value;
document.getElementById('boldStuff2').innerHTML=userInput;
}


</script>
<p>What has a mouth but can't chew?<b id='boldStuff2'>???</b></p>
<input type='text' id='userInput' value='Enter Answer Here'/>
<input type='button' onclick='changeText2()' value='Answer'/>



</head>
</html>
4

2 回答 2

1

该代码的前三行不仅在逻辑上是错误的,而且也是不必要的。尝试一个简单的版本

<script>
function changeText2(){
var userInput=document.getElementById('userInput').value;

if(userInput.toLowerCase()=="river")
{
alert("Good Job");
}

document.getElementById('boldStuff2').innerHTML=userInput;
}


</script>
<p>What has a mouth but can't chew?<b id='boldStuff2'>???</b></p>
<input type='text' id='userInput' value='Enter Answer Here'/>
<input type='button' onclick='changeText2()' value='Answer'/>



</head>
</html>
于 2013-03-14T06:52:59.913 回答
0

在你的 JScript 代码中设置这个函数

   function changeText2(){
     var userInput=document.getElementById('userInput').value;
     if(userInput=="river")
     {
      document.write("");
     }
     document.getElementById('boldStuff2').innerHTML=userInput;
   }
于 2013-03-14T06:54:31.073 回答