菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
82
0

js笔记

原创
05/13 14:22
阅读数 88890
 js搜索框,ajax提交后台,获取文本框的值


<form id="query-ele"> <input type="text" placeholder=" 微信" style="width:200px" class="input-text selectinput" name="wei_xin"> <input type="text" placeholder=" 授权证书号" style="width:200px" class="input-text selectinput" name="certificate"> <button name="" id="" class="btn btn-success" type="button" onclick="chartreload()"> <i class="Hui-iconfont">&#xe665;</i> 搜索</button> <button name="" id="turnNull" class="btn btn-success" type="reset" onclick="tableClear()"> <i class="Hui-iconfont">&#xe6a6;</i> 清空</button> </form>
 function chartreload(){
        if(document.getElementById('query-ele')){
            elearr=document.getElementById('query-ele').getElementsByClassName('selectinput'); // 获取表单中有多少个要搜索的input元素
        }
        this.tjstr={}; // 循环元素个数,将所有表单中的元素挨个循环赋值给tjstr这个数组,
        for(var i=0; i<elearr.length; ++i){
            var name=elearr[i].name;
            this.tjstr[elearr[i].name]=$.trim(elearr[i].value);
        }
        //console.log(this.tjstr); // 此处打印的就是搜索表单的每个input值
        $.ajax({
            url:window.location.pathname,
            data:{tj:this.tjstr},
            type:'POST',
            dataType:"JSON",
            success:function(data){
                if (data["status"]==1){
                    if (data["userInfo"].length != 0){
                        $userInfo=' <tr class="text-c">';
                        $userInfo+='<th defaultcls="" class="undefined" style="width: 50px;">'+data["uid"]+'</th>';
                      
                        $userInfo+='<th defaultcls="" class="undefined" style="width: 100px;">'+data["equityAll"]+'</th>';
                        $userInfo='</tr>';
                        $("#margin").html($userInfo);
                    }
                    if (data["userInfoHistory"].length != 0){
                        $teamDetail="";
                        for (var i=0;i<data["userInfoHistory"].length;i++ ){
                            $teamDetail+=' <tr class="text-c">';
                            $teamDetail+='<th defaultcls="" class="undefined" style="width: 50px;">'+data["userInfoHistory"][i]["u_name"]+'</th>';
                      
                            $teamDetail='</tr>';
                        }
                        $("#detail").html($teamDetail);
                    }
                }else{
                    layer.msg(data["msg"]);
                }
            },
            error:function(data) {
                layer.msg('请求失败,请检查您的网络连接');
            }
        });
    }

 

发表评论

0/200
82 点赞
0 评论
收藏