select,radio 和checkbox动态自动匹配。

来源:互联网 发布:MAC上用Virtual box 编辑:程序博客网 时间:2024/06/05 15:59

 //初始化加载
  $(function(){
  $("[rootinit]").each(function(){
    var $this=$(this);
    var _sel=$this.is("select");
    var _v=$this.attr("rootinit");
    if(_sel){
     $this.val(_v);
    }else{
     $this.find(":radio[value='"+_v+"']").attr("checked","checked");
     if(_v.indexOf(" ")>-1){
      $(_v.split(" ")).each(function(i,n){
       $this.find(":checkbox[value='"+n+"']").attr("checked","checked");
      });
     }
    }
  });
 });

               <li class="divcss" rootinit="${m.workplace}">
                <div class="input" style="width: 530px;">
                  <label>公司地址:</label>
                  <input type="radio" name="mallDesigner.workplace" value="1"  />中大布市
               <input type="radio" name="mallDesigner.workplace" value="2" />柯桥布市
      <input type="radio" name="mallDesigner.workplace" value="3" />其他
    </div>
              <span class="redcol">*</span>
              </li>    

原创粉丝点击