有使用Bootstrap的评论表
<!DOCTYPE html>
<html>
<head>
<title>Comments</title>
</head>
<body>
<form id="commentForm" name="commentForm" onsubmit="return(validate());">
<div class="row">
<div class="col-sm-12 form-group">
<textarea class="form-control" id="comments" name="comments" placeholder="Leave comment..." rows="3"></textarea><br>
<button class="btn pull-right" type="submit">Send</button>
</div>
</div>
</form>
</body>
</html>
我写了一个JS验证
<script type="javascript">
function validate()
{
if( commentForm.comments.value == "" )
{
alert( "Please leave your comment!" );
commentForm.comments.focus() ;
return false;
}
</script>
它将检查一行是否为空,但它根本不起作用。求助于我,我该如何解决?
答案 0 :(得分:0)
你必须像这样检索commentForm元素:
<?php
echo("Names: " . $_POST['dbNames'] . "<br/>\n");
?>
&#13;
function validate() {
// Actually get the DOM element on which you can test value
var commentForm = document.getElementById('commentForm');
if (commentForm.comments.value === '') {
window.alert('Please leave your comment!');
commentForm.comments.focus() ;
return false;
}
}
&#13;
答案 1 :(得分:0)
将脚本代码的类型属性修复为Object[] nodes = Node.returnArray(head);
Node<Integer> returned1 = (Node<Integer>) nodes[0];
Node<Integer> returned2 = (Node<Integer>) nodes[1];
并添加text/javascript
函数的遗漏}