1,一个待验证元素最好是一个id名称,一个name名称,只有id是不行的

2,select 验证  requeired:true 表示验证元素的值不能选择空值

3,从网上摘抄的验证radio checkbox等得代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Test for jQuery validate() plugin</title>

<script src="scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="scripts/jquery.metadata.js" type="text/javascript"></script>
<script src="scripts/jquery.validate.js" type="text/javascript"></script>

<script src="scripts/cmxforms.js" type="text/javascript"></script>
<script type="text/javascript">
// only for demo purposes
$.validator.setDefaults({
	submitHandler: function() {
		alert("submitted!");
	}
});
	
$.metadata.setType("attr", "validate");

$(document).ready(function() {
	$("#form1").validate();
	$("#selecttest").validate();
});
</script>

<style type="text/css">
.block { display: block; }
form.cmxform label.error { display: none; }	
</style>

</head>
<body>

<h1 >jQuery Validation Plugin</a> Demo</h1>
<div >

<form class="cmxform" >
	<fieldset>
		<legend>Validating a form with a radio and checkbox buttons</legend>
		<fieldset>
			<legend>Gender</legend>
			<label for="gender_male">
				<input  type="radio"  />
				Male
			</label>
			<label for="gender_female">
				<input  type="radio" />
				Female
			</label>
			<label for="gender" class="error">Please select your gender</label>
		</fieldset>
		<fieldset>
			<legend>Family</legend>
			<label for="family_single">
				<input  type="radio"  />
				Single
			</label>
			<label for="family_married">
				<input  type="radio"  />
				Married
			</label>
			<label for="family_divorced">
				<input  type="radio"  />
				Divorced
			</label>
			<label for="family_weird">
				<input  type="radio"  />
				Something weird
			</label>
			<label for="family" class="error">Please select your family status.</label>
		</fieldset>
		<p>
			<label for="agree">Please agree to our policy</label>
			<input type="checkbox"  />
			<br/>
			<label for="agree" class="error block">Please agree to our policy!</label>
		</p>
		<fieldset>
			<legend>Spam</legend>
			<label for="spam_email">
				<input type="checkbox"  />
				Spam via E-Mail
			</label>
			<label for="spam_phone">
				<input type="checkbox"  />
				Spam via Phone
			</label>
			<label for="spam_mail">
				<input type="checkbox"  />
				Spam via Mail
			</label>
			<label for="spam[]" class="error">Please select at least two types of spam.</label>
		</fieldset>
		<p>
			<input class="submit" type="submit" value="Submit"/>
		</p>
	</fieldset>
</form>

<form >
	<h2>Some tests with selects</h2>
	<p>
		<label for="jungle">Please select a jungle noun</label><br/>
		<select >
			<option value=""></option>
			<option value="1">Buga</option>
			<option value="2">Baga</option>
			<option value="3">Oi</option>
		</select>
	</p>
	
	<p>
		<label for="fruit">Please select at least two fruits</label><br/>
		<select >
			<option value="b">Banana</option>
			<option value="a">Apple</option>
			<option value="p">Peach</option>
			<option value="t">Turtle</option>
		</select>
	</p>
	
	<p>
		<label for="vegetables">Please select no more than two vergetables</label><br/>
		<select >
			<option value="p">Potato</option>
			<option value="t">Tomato</option>
			<option value="s">Salad</option>
		</select>
	</p>
	
	<p>
		<label for="cars">Please select at least two cars, but no more than three</label><br/>
		<select >
			<option value="m_sl">Mercedes SL</option>
			<option value="o_c">Opel Corsa</option>
			<option value="vw_p">VW Polo</option>
			<option value="t_s">Titanic Skoda</option>
		</select>
	</p>
	
	<p><input type="submit" value="Validate Selecttests"/></p>
</form>

<a href="index.html">Back to main page</a>

</div>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2623402-1";
urchinTracker();
</script>
</body>
</html>

 

 

   

相关文章:

  • 2021-12-09
  • 2021-11-27
  • 2021-11-19
  • 2021-11-19
  • 2021-11-20
  • 2021-11-20
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-08-02
  • 2021-09-05
  • 2021-12-03
  • 2021-11-30
相关资源
相似解决方案