gyfjch01
赵小盛
采纳率40%
2019-07-20 18:18

html后台获取数据怎样才能自动填充到表格中

5
已采纳

[{
"wuliuid": "2",
"shouhuoren": "2",
"mudidi": "2",
"jiesuanfangshi": "2",
"zhongzhuan": "2",
"shouhuorendizhi": "2",
"shouhuorendianhua1": "2",
"shouhuorendianhua2": "2",
"shouhuorendianhua3": null,
"shouhuorendianhua4": null
}]

这是从后台获取的数据

function checkshouhuoren() {
//1获取用户名
var shouhuoren = $("#shouhuoren").val();
//查找信息
$.post("find/findByShr",$("#shouhuoren").serialize(),function (data) {
//
console.log(data)
//自动填充表格数据
//[{"wuliuid":"1","shouhuoren":"1","mudidi":"1","jiesuanfangshi":"1","zhongzhuan":"1","shouhuorendizhi":"1","shouhuorendianhua1":"1","shouhuorendianhua2":"1","shouhuorendianhua3":null,"shouhuorendianhua4":null}]
//目的地
$("#mudidi").val(data.mudidi);
//中转
$("#zhongzhuan").val(data.zhongzhuan);
//详细地址
$("#shouhuorendizhi").val(data.shouhuorendizhi);
//电话1
$("#shouhuorendianhua1").val(data.shouhuorendianhua1);
//\电话2
$("input[name=shouhuorendianhua2]").val(data.shouhuorendianhua2);
//电话3
$("input[name=shouhuorendianhua3]").val(data.shouhuorendianhua3);
//电话4
$("input[name=shouhuorendianhua4]").val(data.shouhuorendianhua4);
//

    });

}



     <tr>
                    <td >
                        <p>收货人信息</p>
                    </td>

                    <td class="td_left">
                        <label for="mudidi" >目的地</label>
                    </td>
                    <td class="td_right">
                        <input type="text" id="mudidi" name="mudidi"  />
                    </td>
                    <td class="td_left">
                        <label for="zhongzhuan">中转</label>
                    </td>
                    <td class="td_right">
                        <input type="text" id="zhongzhuan" name="zhongzhuan" />
                    </td>
                    <td class="td_left">
                        <label for="shouhuorendizhi">详细地址</label>
                    </td>
                    <td class="td_right">
                        <input type="text" id="shouhuorendizhi" name="shouhuorendizhi"/>
                    </td>
                    <td class="td_left">
                        <label for="shouhuorendianhua1">电话1</label>
                    </td>
                    <td class="td_right">
                        <input type="text" id="shouhuorendianhua1" name="shouhuorendianhua1" >
                    </td>
                    <td class="td_left">
                        <label for="shouhuorendianhua2">电话2</label>
                    </td>
                    <td class="td_right">
                        <input type="text" id="shouhuorendianhua2" name="shouhuorendianhua2" >
                    </td>
                    <td class="td_left">
                        <label for="shouhuorendianhua3">电话3</label>
                    </td>
                    <td class="td_right">
                        <input type="text" id="shouhuorendianhua3" name="shouhuorendianhua3">
                    </td>
                    <td class="td_left">
                        <label for="shouhuorendianhua4">电话4</label>
                    </td>
                    <td class="td_right">
                        <input type="text" id="shouhuorendianhua4" name="shouhuorendianhua4" >
                    </td>
                </tr>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • xwh1314 xwh1314 2年前

    试试这个,剩下的也类似
    $("#mudidi").val(data[0].mudidi);

    点赞 评论 复制链接分享
  • asdasde asdasde 2年前

    function checkshouhuoren() {
    //1获取用户名
    var shouhuoren = $("#shouhuoren").val();
    //查找信息
    $.post("find/findByShr",$("#shouhuoren").serialize(),function (data) {
    //
    console.log(data)
    //自动填充表格数据
    //[{"wuliuid":"1","shouhuoren":"1","mudidi":"1","jiesuanfangshi":"1","zhongzhuan":"1","shouhuorendizhi":"1","shouhuorendianhua1":"1","shouhuorendianhua2":"1","shouhuorendianhua3":null,"shouhuorendianhua4":null}]
    //目的地
    $("#mudidi").val(data**[0]**.mudidi);
    //中转
    $("#zhongzhuan").val(data**[0]**.zhongzhuan);
    //详细地址
    $("#shouhuorendizhi").val(data**[0]**.shouhuorendizhi);
    //电话1
    $("#shouhuorendianhua1").val(data**[0]**.shouhuorendianhua1);
    //\电话2
    $("input[name=shouhuorendianhua2]").val(data**[0]**.shouhuorendianhua2);
    //电话3
    $("input[name=shouhuorendianhua3]").val(data**[0]**.shouhuorendianhua3);
    //电话4
    $("input[name=shouhuorendianhua4]").val(data**[0]**.shouhuorendianhua4);
    //

    });
    

    }

    
    
    点赞 评论 复制链接分享
  • dabocaiqq dabocaiqq 2年前

相关推荐