我如何修复,下面的代码中的“预期结束声明”?
<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
答案 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>