基本上,我使用引导程序作为我的 CSS,但我遇到了问题。当我单击按钮 ( id="myQuestionButton") 时,我希望它从输入框 ( id="myInput") 中获取输入并运行它function checkQuestionWords()。
这是与输入和按钮有关的代码块:
<div class="input-append span9 offset3">
  <form>
    <input class="span4" type="text" id="myInput" 
    placeholder="Enter your question."></input>
    <button class="btn" type="submit" id="myQuestionButton">
    Let's check second.</button>
  </form>
</div>
这是它将打印初步结果的地方(现在只是在 a 中<div> </div>):
<div id="results"></div>
到目前为止,这是我的功能:
function checkQuestionWords(){
  var theInput = document.getByElementId("myInput");
  var theQuestion = theInput.trim();
  var questionWords = ["who", "what", "where", "when", "why", "how"];
  var isItGood = false;
for (var i=0, i<7; i++){
  var holder1 = questionWords[i];
  var holder2 = holder1.length;
    if (theQuestion.substr(0,holder2) == questionWords[i]){
      isItGood = true;
      break;}
    else{
      isItGood = false;}}
if (isItGood == false){
  document.getByElementId("results") = "Please enter a question...";}
  //the above just reminds them to begin with a question word; see questionWords
else{
  document.getByElementId("results") = "all is good";}
}
我试着在onclick=checkQuestionWords()"里面做一个整体,<button ...></button>但由于某种原因没有奏效。