jquery实现验证表单非空
表单验证非空,包括空格验证,贴代码:
<html><head><title>input</title><script type="text/javascript" src="jquery.min.js"></script><script type="text/javascript">$(document).ready(function(){$('#error').hide();$('#submit').click(function(event){var data = $('#userId').val();data = $.trim(data);if(data.length < 1) {$('#error').show();event.preventDefault();} else {$('#error').hide();}});});</script></head><body><form id="signup" method="post" action="">user id:<input type="text" id="userId" name="userId" /><span id="error">this field can't be blank</span><br/><input type="submit" id="submit" value="Submit"></form></body></htmL>