Jquery学习笔记之一[常用组件]

1, 全选全不选操作:

<html>
	<head>
		<style type="text/css">
		   body{ font-size:150% }
           td{text-align:center}
	  </style>
	   <!--  引入jquery框架的源码     -->
      <script type="text/javascript" src="jquery-1.8.3.js"></script>
      
	  <script type="text/javascript">
	  	  
	  	  function fun(){
	  	  // jquery支持对一组标签直接设置属性
	  	      $("input[type=checkbox]:gt(0)").prop("checked",  $("#ck1").prop("checked") );
	  	  }
	  	  
	  	  function f1(){
	  	  	// 得到所有被选中的复选框
	  	  	 var len1 = $("input[type=checkbox]:gt(0):checked").length ;
	  	  	 // 得到所有复选框(除了第一个)
	  	  	 var len2 = $("input[type=checkbox]:gt(0)").length;
	  	  	 if( len1 == len2 ){  $("#ck1").prop("checked",true); }	  
	  	  	 else{ $("#ck1").prop("checked",false);  }	  	  
	  	  }
	  	    
	  	  
	  </script>
  </head>
	
	
  <body>
  	 Id: <input type="text" id="id"  style="margin-right:20px"/>
  	 Name: <input type="text" id="name" style="margin-right:20px"/> 
  	 Price:<input type="text" id="price"/>
  	 <input type="button" value="add" style="margin-left:20px"/>
  	 
  	 <hr size="2"/>
  	 
  	 <p> &nbsp; </p>
     <table border="1" bordercolor="blue" cellspacing="0" width="70%" align="center">
       <tbody id="tbody">
          <tr bgcolor="lightblue" align="center"> 
          	  <td><b> <input type="checkbox" id="ck1" onclick="fun()"/> </b></td>
              <td><b> Id </b></td>
              <td><b> Name </b></td>
			  <td><b> Price </b></td>
			  <td><b> Count </b></td>
			  <td><b> Total_Price </b></td>
              <td><b> Delete </b> </td>
          </tr>
          <tr> 
              <td> <input name="a1" onclick="f1()" type="checkbox" /> </td>
              <td> 1 </td>
              <td>Iphone6</td>
			  <td>5000</td><td><input type="button" value="-"/><input type="text" size="2" value="1"/><input type="button" value="+"/></td><td>5000</td>
              <td> <input type="button" value="delete"/> </td>
          </tr>
          <tr> 
              <td> <input name="a1" onclick="f1()" type="checkbox" /> </td>
              <td> 2 </td>
              <td>IPad</td>
			  <td>2000</td><td><input type="button" value="-"/><input type="text" size="2" value="1"/><input type="button" value="+"/></td><td>2000</td>
              <td> <input type="button" value="delete"/> </td>
          </tr>
          
<tr>  
              <td> <input name="a1" onclick="f1()" type="checkbox" /> </td>
              <td> 3 </td>
              <td>Apple</td>
			  <td>7</td><td><input type="button" value="-"/><input type="text" size="2" value="1"/><input type="button" value="+"/></td><td>7</td>
              <td> <input type="button" value="delete"/> </td>
          </tr>
          <tr>  
              <td> <input name="a1" onclick="f1()" type="checkbox" /> </td>
              <td> 3 </td>
              <td>Apple</td>
			  <td>7</td><td><input type="button" value="-"/><input type="text" size="2" value="1"/><input type="button" value="+"/></td><td>7</td>
              <td> <input type="button" value="delete"/> </td>
          </tr>
          <tr>  
              <td> <input name="a1" onclick="f1()" type="checkbox" /> </td>
              <td> 3 </td>
              <td>Apple</td>
			  <td>7</td><td><input type="button" value="-"/><input type="text" size="2" value="1"/><input type="button" value="+"/></td><td>7</td>
              <td> <input type="button" value="delete"/> </td>
          </tr>
     </table>
     <div style="text-align:center">
          <input type="button" value="select all" style="margin-right:20px"/>
          <input type="button" value="delete all select" style="margin-right:20px"/>
          <input type="button" value="取消选中" style="margin-right:20px"/>
     </div>
  </body>
</html>

2.1, 用jquery搜索框下拉列表更换URL

<html>
    <head>
       <meta http-equiv="content-type" content="text/html;charset=GBK"/>    
       <style type="text/css">
           span{ color:red ; font-size:82.5% ; margin-left:5px ; font-weight:bolder }
           .ok{ color:green }
       </style>
       <script type="text/javascript" src="/jquery_day1/jquery-1.8.3.js"></script>
       <script type="text/javascript">
            
            function fun(){
               var val = $("#qc option:selected").val();
               if( val=="name" ){  $("#f1").prop("action","/xxx/NameAction");      }
               if( val=="mobile"){  $("#f1").prop("action","/xxx/MobileAction"); }
               if( val=="email"){  $("#f1").prop("action","/xxx/EmailAction");  }       
            }  
       </script>
    </head>
    <body>
       <form action="" method="get" id="f1">
           <select id="qc" name="qc" onchange="fun()">
               <option>请选择</option>
               <option value="name">按名字搜索</option>
               <option value="mobile">按手机号码搜索</option>
               <option value="email">按email邮箱搜索</option>
           </select>
           <input type="text" name="qcv" id="qcv"/>
           <input type="submit" value="搜索"/>
       </form>
    </body>
</html>

2.2, 用js搜索框下拉列表更换URL


<html>
    <head>
       <meta http-equiv="content-type" content="text/html;charset=GBK"/>    
       <style type="text/css">
           span{ color:red ; font-size:82.5% ; margin-left:5px ; font-weight:bolder }
           .ok{ color:green }
       </style>
       
       <script type="text/javascript">
            
            function fun(){
               //获取下拉列表
               var qc = document.getElementById("qc");
               // 获取所有option
               var ops = qc.options; 
               // 获取被选中的option的下标
               var idx = qc.selectedIndex;
               // 获取被选中的值
               var val = ops[idx].value;
               //设置form标签的action属性
               var f1 = document.getElementById("f1");
               if( val == "name" ) f1.action="/js_day2/NameAction";
               if( val == "mobile") f1.action="/js_day2/MobileAction";
               if( val == "email") f1.action="/js_day2/EmailAction";
            }
            
       </script>
    </head>
    <body>
       <form action="" method="get" id="f1">
           <select id="qc" name="qc" onchange="fun()">
               <option>请选择</option>
               <option value="name">按名字搜索</option>
               <option value="mobile">按手机号码搜索</option>
               <option value="email">按email邮箱搜索</option>
           </select>
           <input type="text" name="qcv" id="qcv"/>
           <input type="submit" value="搜索"/>
       </form>
    </body>
</html>

3, 用JS联级下拉列表框


<html>
    <head>
       <meta http-equiv="content-type" content="text/html;charset=GBK"/>    
       <style type="text/css">
      
       </style>
       
       <script type="text/javascript">
           
           var liaoning = [{text:"沈阳",value:"shenyang"},{text:"铁岭",value:"tieling"},{text:"大连",value:"dalian"}];
           var henan = [{text:"郑州",value:"zhengzhou"},{text:"信阳",value:"xinyang"},{text:"安阳",value:"anyang"}]; 
           
           // 定义一个函数,获取省份对应的数组
           function getArray(prov){
              if( prov=="liaoning" ) return liaoning;
              if( prov=="henan") return henan;
           }
           
           function selectCitys(tag){
              // 此处tag代表 province 下拉列表
              // options    selectedIndex 
              var prov = tag.options[ tag.selectedIndex ].value; 
              // 获取prov对应的数组
              var array = getArray(prov);
              // 获取城市下拉列表
              var city = document.getElementById("city");
              // 清空city下拉列表
              city.options.length = 0;
              // 将数组里的数据存入city下拉列表
              for( var i=0;i<array.length;i++){
                 city.options[i] = new Option( array[i].text , array[i].value );
              }
           }
           
       </script>
    </head>
    <body>
        <select name="province" onchange="selectCitys(this)">
            <option>请选择省份</option>
            <option value="liaoning">辽宁</option>
            <option value="henan">河南</option>
        </select>
        <select name="city" id="city">
            <option>请选择城市</option>
        </select>
    </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

java我跟你拼了

您的鼓励是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值