我想在使用jQuery和javascript單擊按鈕後驗證表單的輸入值。如何驗證表單的輸入值
現在,如果我輸入一個值作爲輸入,然後單擊提交輸入字段,按鈕就會消失。任何想法我在這裏錯了嗎?
HTML文件...
<!DOCTYPE html>
<html>
<head>
<title></title>
<link/>
<script type='text/javascript' src='script.js'></script>
</head>
<body>
<form>
<input type="text" id='input_1'>
<input type="submit" value="Send" id="send">
</form>
</body>
</html>
腳本文件...
$(document).ready(function() {
$('.send').click(function() {
validateInput(document.getElementById('#input_1'));
function validateInput(inputValue){
if (inputValue === 3) {
alert("Element cannot be equal to 3");
}
}
});
});
[最佳的jQuery表單插件。輕鬆驗證任何使用「beforeSubmit」選項](http://malsup.com/jquery/form/#ajaxForm) – SpYk3HH 2013-05-06 15:10:38
'click(function(event){event.preventDefault();'將停止執行表單提交 – Eraden 2013-05-06 15:10:58
另外不要使用'click()'。請使用'on('click',...' – Eraden 2013-05-06 15:11:50