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

表单动态更新部门与用户
本文介绍了一个基于GSP的表单实现方案,通过选择不同的部门时动态更新部门及对应的用户列表,并自动填充选中用户的电话号码。
<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("");
               }
           });          
   }

  

转载于:https://www.cnblogs.com/yu0312chao/p/4863361.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值