如何修复预期的声明结束?

时间:2013-12-09 19:47:57

标签: javascript hta

我如何修复,下面的代码中的“预期结束声明”?

  <script type="text/javascript">
function substitute() {
  var myValue = document.getElementById('myTextBox').value;

  if (myValue.length === 0) {
    alert('Please enter a real value in the text box!');
    return;
  }
  var myTitle = document.getElementById('title');
  myTitle.innerHTML = myValue;

}
</script>

它一直告诉我第57行是这一行:

  <input type="submit" value="Click Me" onClick="substitute();">

以下是完整的HTA链接: http://pastebin.com/fMg5e4RN

1 个答案:

答案 0 :(得分:1)

使用<form onsubmit="return substitute()"并根据验证返回true或false。删除type =“javascript”或将其修复为text / javascript

<script type="text/javascript">
function substitute() {
  var myValue = document.getElementById('myTextBox').value;

  if (myValue.length === 0) {
    alert('Please enter a real value in the text box!');
    return false;
  }
  // not sure what the following two lines are for
  var myTitle = document.getElementById('title');
  myTitle.innerHTML = myValue;
  return true; // allow submit

}
</script>

并使用

<form action="some action"  onsubmit="return substitute();">
  <input type="text" id="myTextBox"/>
  <input type="submit" value="Click Me" />
 </form>