当前位置: 代码迷 >> Web前端 >> 自个儿写的jquery的一些入门例子
  详细解决方案

自个儿写的jquery的一些入门例子

热度:104   发布时间:2012-11-05 09:35:12.0
自己写的jquery的一些入门例子
<script type="text/javascript">
	//window.onload();   body的onload()事件
	//可以出现多个,执行顺序跟代码编写顺序一致
	//$(document).ready(function() {
	//	alert("first");
	//});
	//$(document).ready(function() {
	//	alert("second");
	//});
	$(function() {
		//var tdStr = $("#td");//获取id='td'的对象
		//alert(tdStr.html());//返回指定元素id='td'的HTML值
		//tdStr.html("添加");//将‘添加’字符设置到指定元素id='td'中
		//循环显示class='iname'的值
		//$.each($("table tr .iname"), function() {
			//alert(this.value);
		//});
		//clear按钮的点击事件
		$("#clear").click(function() {
			alert("点我清除");
		});
		$("form[1]").submit(function(){$("#commentForm").validate();});
		$("button").click(function () { 
			$("div").each(function (index, domEle) { 
			  // domEle == this 
			  $(domEle).css("backgroundColor", "yellow");  
			  if ($(this).is("#stop")) { 
				  $("span").text("Stopped at div index #" + index); 
				  return false; 
			  } 
			});
		});
	});		
</script>
<body>
<button>Change colors</button>
<span></span> 
<div>a</div> 
<div>b</div>

<div>c</div> 
<div>d</div>
<div id="stop">Stop here</div> 
<div>e</div>

<div>f</div>
<div>g</div>

<form action="#">
<table>
	<tr id="tr">
		<td id="td">you<br>
		<input name="name" value="ceshi1" class="iname" /></td>
	</tr>
	<tr>
		<td><a href="#" class="hf">try</a><input name="name"
			value="ceshi2" class="iname" /></td>
	</tr>
	<tr>
		<td><input type="submit" value="submit"></input> <input type="button"
			value="clear" id="clear" /></td>
	</tr>
</table>
</form>
<form class="cmxform" id="commentForm" method="get" action="">
<fieldset>  
   <p>  
     <label for="cname">Name</label>  
     <em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />  
   </p>  
   <p>  
     <label for="cemail">E-Mail</label>  
     <em>*</em><input id="cemail" name="email" size="25"  class="required email" />  
   </p>  
   <p>  
     <label for="curl">URL</label>  
     <em>  </em><input id="curl" name="url" size="25"  class="url" value="" />  
   </p>  
   <p>  
     <label for="ccomment">comment</label>  
     <em>*</em><textarea id="ccomment" name="comment" cols="22"  class="required"></textarea>  
   </p>  
   <p>
   	<label for="date">datetime</label>
   	<input id="cdate" name="date" class="dateISO">
   </p>  
   <p>  
     <input class="submit" type="submit" value="Submit"/>  
   </p>
 </fieldset>  
</form>
</body>
  相关解决方案