Menu
Woocommerce Menu

Jquery获取复选框被选中值的简单方法,Javascript实现动态菜单添加的实例代码

0 Comment

//调用例子:bradio.namespace(“bradio.lang.array”);
 //下边是百度编写翻译后的源码,变量都是a,b,c,d…之后我会重新写三个标准点的。
 //好了,最初解析
 bradio.namespace = function () { //创设命名空间
     var a = arguments, //[“bradio.lang.array”]
         b = null, //用于寄放上顶级对象
         c, d, e, f;
//c是计数器,d是内层循环的计数器,e是拆分后命名空间数组,f是arguments参数长度
     c = 0;
     for (f = a.length; c < f; c++) {
         e = (“” + a[c]).split(“.”); //拆分命名空间,拆分后
[“bradio”, “lang”, “array”]
         b = bradio; //基础对象,基于那一个指标实行命名空间的增进
         for (d = “bradio” == e[0] ? 1 : 0; d < e.length; d++)
//假如第叁个是bradio, 就首个最初遍历 [“bradio”,”lang”,”array”]
             b[e[d]] = b[e[d]] || {}, b = b[e[d]]
             //其实相当于
             //b[e[d]] = b[e[d]] || {}
//要是当前指标已经操作就用当下目的,不真实就赋值空对象
             //b = b[e[d]]
//用字对象覆盖b,接下去的循环基于子对象增多命名空间
     }
     return b//重临最终一层对象
 };

复制代码 代码如下:

$(document).ready(function () { 
    //找到七个下拉框  
    var ProvinceSelect = $(“.Province”).children(“select”); 
    var CitySelect = $(“.City”).children(“select”); 
    var AreaSelect = $(“.Area”).children(“select”); 
    var AddressSelect=$(“.AddressSelect”); 
银河国际网址手机版,    //给第三个下拉框注册事件  
    ProvinceSelect.change(function () { 
        //1、获取当前下拉框的值  
         var ProvinceValue = $(this).val(); 
        //1.1只要第二个下拉框内容有变化,第八个下拉框将在遮蔽起来  
        AreaSelect.parent().hide(); 
        AddressSelect.hide(); 
        AddressSelect.html(“”); 
        //2、若是值不为空,则显得城市下拉框  
         if (ProvinceValue != “”) { 
                   CitySelect.html(“”); 
                   $(“<option value=”>Please Choose
City</option>”).appendTo(CitySelect); 
                    switch(ProvinceValue) 
                       { 
                       
//实际项目中,那么些城墙数组断定是在服务器获取的,这里为了便利,笔者就径直自定义了二个数组  
                       
//假使追求八面见光,这里还能加一道缓存,防止重复获取  
                       case “HeBei”: 
                            var
CityOfHeBei=[“ShiJiaZhuang”,”CangZhou”,”LangFang”];  
                            for(var i=0;i<CityOfHeBei.length;i++){ 
                                $(“<option
value='”+CityOfHeBei[i]+”‘>”+CityOfHeBei[i]+”</option>”).appendTo(CitySelect); 
                            } 
                             break; 
                       case “ShanDong”: 
                            var
CityOfShanDon=[“JiNan”,”DeZhou”,”QingDao”];      
                            for(var
i=0;i<CityOfShanDon.length;i++){ 
                                $(“<option
value='”+CityOfShanDon[i]+”‘>”+CityOfShanDon[i]+”</option>”).appendTo(CitySelect); 
                            } 
                            break; 
                       } 
                 CitySelect.parent().show();    
        } else { 
            CitySelect.parent().hide(); 
        } 
    }); 
    //给第贰个下拉框注册事件  
     CitySelect.change(function () { 
            var CityValue = $(this).val();       
            AddressSelect.hide(); 
            AreaSelect.parent().hide();  
            AddressSelect.html(“”); 
             if (CityValue != “”) { 
                   AreaSelect.html(“”); 
                   $(“<option value=”>Please Choose
Area</option>”).appendTo(AreaSelect); 
                    switch(CityValue) 
                       { 
                      
//实际项目中,这些区数组分明是在服务器获取的,这里为了省事,笔者就一贯自定义了二个数组  
                      
//纵然追求完善,这里还足以加一道缓存,幸免再一次获取  
                       case “ShiJiaZhuang”: 
                            var
AreaOfCity=[“GaoXinQu”,”KaiFaQu”,”XinHuaQu”];    
                            for(var i=0;i<AreaOfCity.length;i++){ 
                                $(“<option
value='”+AreaOfCity[i]+”‘>”+AreaOfCity[i]+”</option>”).appendTo(AreaSelect); 
                            } 
                             break; 
                       case “CangZhou”: 
                            var
AreaOfCity=[“XinHuaQu”,”YunHeQu”];       
                            for(var i=0;i<AreaOfCity.length;i++){ 
                                $(“<option
value='”+AreaOfCity[i]+”‘>”+AreaOfCity[i]+”</option>”).appendTo(AreaSelect); 
                            } 
                            break; 
                       case “LangFang”: 
                            var
AreaOfCity=[“AnCiQu”,”GuangYangQu”]; 
                            for(var i=0;i<AreaOfCity.length;i++){ 
                                $(“<option
value='”+AreaOfCity[i]+”‘>”+AreaOfCity[i]+”</option>”).appendTo(AreaSelect); 
                            } 
                            break; 
                       case “QingDao”: 
                            var
AreaOfCity=[“GaoXinQu”,”KaiFaQu”,”XinHuaQu”];    
                            for(var i=0;i<AreaOfCity.length;i++){ 
                                $(“<option
value='”+AreaOfCity[i]+”‘>”+AreaOfCity[i]+”</option>”).appendTo(AreaSelect); 
                            } 
                             break; 
                       case “DeZhou”: 
                            var
AreaOfCity=[“XinHuaQu”,”YunHeQu”];       
                            for(var i=0;i<AreaOfCity.length;i++){ 
                                $(“<option
value='”+AreaOfCity[i]+”‘>”+AreaOfCity[i]+”</option>”).appendTo(AreaSelect); 
                            } 
                            break; 
                       case “JiNan”: 
                            var
AreaOfCity=[“AnCiQu”,”GuangYangQu”]; 
                            for(var i=0;i<AreaOfCity.length;i++){ 
                                $(“<option
value='”+AreaOfCity[i]+”‘>”+AreaOfCity[i]+”</option>”).appendTo(AreaSelect); 
                            } 
                            break; 
                       } 
                     AreaSelect.parent().show();  
             } else { 
                     AreaSelect.parent().hide(); 
            } 
    }); 
    AreaSelect.change(function(){ 
            var AreaValue=$(this).val(); 
            AddressSelect.html(“”); 
            if (AreaValue!=””){ 
                $(“<span>The Address Is –Province:
“+ProvinceSelect.val()+”  City: “+CitySelect.val()+”  Area:
“+AreaSelect.val()+”</span>”).appendTo(AddressSelect); 
            AddressSelect.show(); 
            //alert(“The Address Is  Province: “+ProvinceSelect.val()+” 
City: “+CitySelect.val()+”  Area: “+AreaSelect.val());  
                }                   
     }) 
}); 

理所当然只是笔者的接头,假若哪儿不是很对,还请各位英豪扶助提议,避防误导了我们。

<input type=”button” id=”btn5″ value=”获得选中的保有值”>
<input type=”text” name=”dd” id=”dd” size=”50″  />
$(“#btn5”).click(function(){
          var str=””;
                $(“[name=’checkbox’][checked]”).each(function(){
                    str+=$(this).val()+”,”;
                })
                $(“#dd”).val(str)
          })

你只怕感兴趣的篇章:

  • JS打字效果的动态菜单代码分享
  • JavaScript
    下拉菜单达成代码
  • 二个日期下拉菜单的js完结代码
  • Js点击弹出下拉菜单效率实例
  • JavaScript多级下拉菜单代码(简单实用)
  • 下拉菜单点击完毕延续跳转职能的js代码
  • js
    单击式的下拉菜单效果实例
  • JavaScript结合PHP完结网页制作中双下拉菜单的动态完结

你或然感兴趣的篇章:

  • namespace.js
    Javascript的命名空间库
  • javascript
    面向对象,达成namespace,class,承接,重载
  • JavaScript创制命名空间(namespace)的最简达成
  • javaScript NameSpace
    轻松表达介绍

你也许感兴趣的文章:

  • jQuery达成选中弹出窗口采用框内容后赋值给文本框的不二等秘书籍
  • jquery获取复选框被入选的值
  • 各类选拔框jQuery的入选方法(实例讲授)

Javascript源码

//bradio.namespace(“bradio.lang.array”);
  bradio.namespace = function () { //创设命名空间
      var args = arguments,
          parent = null,
          arr, i, j, len;
      for (i=0, len = args.length; i < len; i++) {
          arr = (“” + args[i]).split(“.”);
          parent = bradio;
          for(j = “bradio” == arr[0] ? 1 : 0; j < arr.length; j++)
{
              parent[ arr[j] ] = parent[ arr[j] ] || {};
              parent = parent[ arr[j] ];
          }
      }
      return parent;
  }

复制代码 代码如下:

标签:,

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章

网站地图xml地图