jquery - 实例1
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="text2.aspx.cs" Inherits="Jquery_t.text2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript" src="Scripts/jquery-1.8.2.js"></script> <script type="text/javascript"> $(document).ready(function () { var x = 10; var y = 20; var $mytitle = ""; $("#biaoji").mouseover(function (event) { $mytitle = this.title; this.title = ""; //var tooltip = "<div id='tooltip'>" + $mytitle + "</div>"; var tooltip = "<div id='tooltip'><img src='Images/2.jpg' />"+"<br/>"+$mytitle+"</div>"; $("body").append(tooltip); $("#tooltip").css ( { "top": (event.pageY+y) + "px", "left": (event.pageX+x) + "px" } ).show("fast"); }).mouseout(function () { $("#tooltip").remove(); this.title = $mytitle; }).mousemove(function (e) { $("#tooltip").css ({ "top": (event.pageY+y) + "px", "left": (event.pageX+x) + "px" }); }); $("#content").hide();//隐藏div //绑定click事件,如果id为的content的内容为空则让它显示,否则就隐藏 //$("h3").bind("click", function () { // if ($("#content").is(":visible")) { // $(this).next("div #content").hide(); // } // else { // $(this).next("div #content").show(); // } //}); //下面这个hover是jquery的合成事件,光标划进和划出分别会执行的两个函数,还有一个合成函数是toggle,是点击 $("h3").hover(function () { $(this).next("div #content").show(3000); }, function(){ $(this).next("div #content").hide(3000); }) //toggle里面可以有多个方法,会依次执行完,然后重新开始执行第一次,如此循环 $("h3").toggle(function () { alert("第一次哦!"); }, function () { alert("第二次哦!"); }, function () { alert("第三次哦!"); }, function () { alert("第四次哦!"); }); //id为btn的按钮绑定了一个myclick的自定义事件,s1,s2两个自定义参数 $("#btn").bind("myclick", function (event,s1,s2) { alert("my 自定义事件"); $("body").append("<p>" + s1 + s2 + "</p>"); //$("#content1").toggle(); }) //页面加载完之后自动触发事件 //$("#btn").trigger("myclick",["下雨","刮风"]); $("#bigger").click(function () { if (!$("bigtext").is(":animated")) {//判断是否处于动画 if ($("#bigtext").height() < 500) { $("#bigtext").animate({ height: "+=50" }, 400);//scrolltop这里属性可以控制多行文本框的滚动条的位置 } } }); $("#smaller").click(function () { if (!$("bigtext").is(":animated")) { if ($("#bigtext").height() > 50) { $("#bigtext").animate({ height: "-=50" }, 400); } } }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <p><a href="#" id="biaoji" title="我的标记">标dsadsadsadsadas记</a></p> </div> <div id="content1" style="border: thin double #800000; background-color: #FFFFFF; width: 300px; height: 200px;" > <h3>what it's this?</h3> <div id="content" style="border-style: double none none none; border-width: thin; border-color: #800000; background-color: #FFFFFF; " > this's jQuery,a funtastic javascript tool<br/> this's jQuery,a funtastic javascript tool<br/> this's jQuery,a funtastic javascript tool<br/> this's jQuery,a funtastic javascript tool<br/> this's jQuery,a funtastic javascript tool<br/> </div> </div> <input type="button" id="btn" value="button" /><br/> <span id="bigger">bigger</span> <span id="smaller">smaller</span> <div> <textarea id="bigtext" rows ="8" cols ="20"> wewewewewewewewewewe ewwewewewewewewewewe ewwewewewewewewewewe ewwewewewewewewewewe ewwewewewe ewwewewewe </textarea> </div> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="text3.aspx.cs" Inherits="Jquery_t.text3" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript" src="Scripts/jquery-1.8.2.js"></script> <script type="text/javascript" > $().ready(function () { $("#add").click(function () {//把左边的选中项添加到右边 var $option = $("#select1 option:selected"); $option.remove().appendTo("#select2"); }); $("#add_all").click(function () {//把左边的全部项添加到右边 var $option = $("#select1 option"); $option.remove().appendTo("#select2"); }); $("#select1").dblclick(function () {//左边的选中项双击添加到右边 var $option = $("#select1 option:selected"); $option.remove().appendTo("#select2"); }); $("#remove").click(function () { var $option = $("#select2 option:selected"); $option.remove().appendTo("#select1"); }); $("#remove_all").click(function () { var $option = $("#select2 option"); $option.remove().appendTo("#select1"); }); $("#select2").dblclick(function () { var $option = $("#select2 option:selected"); $option.remove().appendTo("#select1"); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <div style="top:100px;left:100px;width :200px;"> <select multiple id="select1" style="width:100px;height:160px"> <option value="1">一号</option> <option value="2">二号</option> <option value="3">三号</option> <option value="4">四号</option> <option value="5">五号</option> <option value="6">六号</option> <option value="7">七号</option> <option value="8">八号</option> </select> <div style="top:100px;left:300px;"> <span id="add">选中项添加到右边>></span><br/> <span id="add_all">全部添加到右边>></span> </div> </div> <div style="top:100px;left:300px;width :200px;"> <select multiple id="select2" style="width:100px;height:160px;"> </select> <div style="top:100px;left:300px;"> <span id="remove"><<选中项移到左边</span><br/> <span id="remove_all"><<全部移到左边</span> </div> </div> </div> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test4.aspx.cs" Inherits="Jquery_t.test4" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <style type="text/css"> .right { color:green; } .wrong { color:red; } </style> <script type="text/javascript" src="Scripts/jquery-1.8.2.js"></script> <script type="text/javascript"> $(document).ready(function () { var err=""; $("form :input").blur(function () { var $parent = $(this).parent(); $parent.find(".right").remove();//移除添加上去的提示,按照class查找 $parent.find(".wrong").remove(); if($(this).is("#username")) { if (this.value == "" || this.value.length < 6) { err = "请至少输入6位的用户名"; $parent.append("<span class='wrong'>" + err+ "</span>"); } else { $parent.append("<span class='right'> " + "用户名输入成功" + "</span>"); } } if ($(this).is("#email")) { if (this.value == "" || (this.value != "" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value))) { err = "请输入正确的邮箱"; $parent.append("<span class='wrong'>" + err + "</span>"); } else { $parent.append("<span class='right'> " + "邮箱输入成功" + "</span>"); } } }); $("#send").click(function () { if (err !="" || $("#username").attr("value") == "" || $("#email").attr("value")=="" )//判断错误值是否为空,还有用户名和邮箱是否为空 { return false; } alert("成功!"); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <label for="username">用_户_名:</label> <input type="text" id="username" /> </div> <div> <label for="email">邮____箱:</label> <input type="text" id="email" /> </div> <div> <label for="personinfo">个人资料:</label> <input type="text" id="personinfo" /> </div> <div> <input type="submit" value="提交" id="send" /> <input type="reset" id="res" /> </div> <div> </div> </form> </body> </html>
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <div> 已有评论: </div> <div> <h5>张三;</h5> <p>沙发</p> </div> <div> <h5>李四;</h5> <p>板凳</p> </div> <div> <h5>王五;</h5> <p>桌子</p> </div> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ajax_test1.aspx.cs" Inherits="Jquery_t.ajax_test1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript" src="Scripts/jquery-1.8.2.js"></script> <script type="text/javascript"> $().ready(function () { $("#send").click(function () { $("#load_text").load("ajax_test.html"); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" id="send" value="Ajax获取" /> <div id="load_text"></div> </div> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test1.aspx.cs" Inherits="Jquery_t.test1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type ="text/javascript" src="../Scripts/jquery-1.8.2.js" ></script> <script type ="text/javascript" > $(document).ready(function(){ $("button").click(function(){ $("p").hide(); $(".panel").slideToggle(100); }); $("#sure").click(function () { if ($("#sure").is(":checked")) { alert("感谢您的支持."); } }) $("#selectall").click(function () {//全选控制单选 $('[name=items]:checkbox').attr("checked", this.checked);//把所有的checkbox的checked状态都等于这个全选的状态 }); //属性name等于items的checkbox元素 $('[name=items]:checkbox').click(function () {//单选控制全选 var $temp = $('[name=items]:checkbox');//把所有单选的checkbox保存到变量,避免使用同一个选择器变量,提高程序运行的效率 $("#selectall").attr('checked', $temp.length == $temp.filter(':checked').length);//attr('checked',true/false)原型 }) //过滤表格里行的文本内容 $("#filter").keyup(function () { $("table tbody tr") .hide() .filter(":contains('" + ($("#filter").val()) + "')") .show(); }); var $cat = $('ul li:gt(5):not(:last)'); $cat.hide(); //$("#more").click(function () { // if ($cat.is(":visible")) { // $cat.hide(); // } // else { // $cat.show(); // } //}); //上面注释的方法和这个是等价的,下面的toggle这种方式,会切换的执行下面两个函数 $("#more").toggle(function () { $cat.hide(); }, function() { $cat.show(); } ); //当idweiaddress的文本框得到焦点时,如果文本框的内容是“请输入地址”,则把文本框的值置为空 $("#address").focus(function () { var $vall = $(this).val(); if ($vall == "请输入地址") { $(this).val(""); } }); //当id为address的文本框失去焦点时触发,如果文本框的内容为空,则把文本框的值置为“请输入地址” $("#address").blur(function () { var $vall = $(this).val(); if ($vall == "") { $(this).val("请输入地址"); } }) $("#address").css("color", "#ff00cc"); $("#address").css("opacity", "0.4"); //单机li元素会在ul尾部插入li元素的复制品 //$("ul li").click(function () { // $(this).clone().appendTo("ul"); //}); $("#panel").toggle(function () { $(this).animate({ left: "500px",height:"200px" ,top:"300px"}, 3000); },function(){ $(this).animate({ left: "10px", height: "-=100px" ,top:"100px"}, 3000,function(){$(this).css("background" ,"#ffcc33");}); }); }); </script> <title></title> <style type="text/css"> #panel{ position:relative; width:100px; height:100px; border:1px solid #66a997; background :#ff0000; cursor:pointer; } div.panel,p.flip { margin:0px; padding:5px; text-align:center; background:#e5eecc; border:solid 1px #c3c3c3; } div.panel { height:120px; display:none; } </style> </head> <body> <form id="form1" runat="server"> <div> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button type="button">Click me</button> <div> <input type ="checkbox" id="sure" /><label for="sure" >我已经阅读完上面的规章制度了.</label> </div> </div> <div class="panel"> <p>W3School - 领先的 Web 技术教程站点</p> <p>在 W3School,你可以找到你所需要的所有网站建设教程。</p> </div> <div> <input type ="checkbox" id="selectall" />全选/全不选<br /> <input type ="checkbox" name="items" value ="足球" />足球 <input type ="checkbox" name="items" value ="篮球" />篮球 <input type ="checkbox" name="items" value ="网球" />网球 <input type ="checkbox" name="items" value ="羽毛球" />羽毛球 <input type ="checkbox" name="items" value ="乒乓球" />乒乓球 </div> <div> <br/> 筛选: <input id="filter" /> <br/> </div> <div> <table> <thead> <tr><th>姓名</th><th>性别</th><th>暂住地</th></tr> </thead> <tbody> <tr><td>张山</td><td>男</td><td>浙江宁波</td></tr> <tr><td>李四</td><td>女</td><td>浙江杭州</td></tr> <tr><td>王五</td><td>男</td><td>湖南长沙</td></tr> <tr><td>找六</td><td>男</td><td>浙江温州</td></tr> <tr><td>Rain</td><td>男</td><td>浙江杭州</td></tr> <tr><td>MAXMAN</td><td>女</td><td>浙江杭州</td></tr> <tr><td>王六</td><td>男</td><td>浙江杭州</td></tr> <tr><td>李字</td><td>女</td><td>浙江杭州</td></tr> <tr><td>李四</td><td>男</td><td>湖南长沙</td></tr> </tbody> </table> </div> <div> <ul> <li>bmw<i>2333</i></li> <li>benz<i>2333</i></li> <li>aodi<i>2333</i></li> <li>suzuki<i>2333</i></li> <li>luhu<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> <li>sony<i>2333</i></li> </ul> </div> <input type ="button" id="more" value ="more" /> <input type="text" id="address" value="请输入地址" /> <div id="panel"></div> </form> </body> </html>
年轻过得闲,以后被人嫌...
年轻累不死....