grails之二级联动后的文本框内容的切换

<td colspan="2">
        <staff:getDeptHtml  name="dept" value="" class="y-select dept" />   
        <span class="userTd"><staff:getUsersHtml name="user"  value="" class="y-select user"/> </span>
              <input type="text" id="usepersonphone"  name="usepersonphone" 
                   onkeyup="this.value = this.value.replace(/[^\d.]/g, '')"  onafterpaste="this.value=this.value.replace(/\D/g,'')"
                        class="y-textbox" style="width:150px;"  >

  </td>

 <g:formRemote name="myForm" onSuccess="deptChangeSucc(data)" class="deptChange" url="[controller: 'memberCarRepair', action: 'changeDept']">
        <input type="hidden" name="deptid" id="deptid" type="text" />
 </g:formRemote>  
$(document).ready(function () {
           $(".dept").change(function(){
               var deptid = $(this).val()
              
               $(".deptChange #deptid").val(deptid);
               $(".deptChange").submit();
           });
    });

 function deptChangeSucc(data){
        $(".userTd").html(data)
        checkApplyPhone()
    }

 function checkApplyPhone(){
            $("select[name='user']").change(function(){
               var val = $(this).val()
               if(val!=''){
                   $.ajax({
                      type: "post",//使用get方法访问后台
                      url: "<%=request.getContextPath()%>/memberCooperate/ajaxSelUser",//要访问的后台地址
                      data: "id="+val,//要发送的数据
                      success: function(msg){//msg为返回的数据,在这里做数据绑定
                        $("#usepersonphone").val(msg.phone)
                        $("#useperson").val(msg.realname)
                      }
                  });
               }else{
                   $("#usepersonphone").val("");
               }
           });          
   }

  

posted @ 2015-10-09 11:06  yu0312chao  阅读(270)  评论(0编辑  收藏  举报