自己写的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" /></td></tr><tr><td><a href="#" /></td></tr><tr><td><input type="submit" value="submit"></input> <input type="button"value="clear" id="clear" /></td></tr></table></form><form id="commentForm" method="get" action=""><fieldset> <p> <label for="cname">Name</label> <em>*</em><input id="cname" name="name" size="25" minlength="2" /> </p> <p> <label for="cemail">E-Mail</label> <em>*</em><input id="cemail" name="email" size="25" /> </p> <p> <label for="curl">URL</label> <em> </em><input id="curl" name="url" size="25" value="" /> </p> <p> <label for="ccomment">comment</label> <em>*</em><textarea id="ccomment" name="comment" cols="22" name="date" type="submit" value="Submit"/> </p> </fieldset> </form></body>