zoukankan      html  css  js  c++  java
  • js笔记

     js搜索框,ajax提交后台,获取文本框的值


    <form id="query-ele"> <input type="text" placeholder=" 微信" style="200px" class="input-text selectinput" name="wei_xin"> <input type="text" placeholder=" 授权证书号" style="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=" 50px;">'+data["uid"]+'</th>';
                          
                            $userInfo+='<th defaultcls="" class="undefined" style=" 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=" 50px;">'+data["userInfoHistory"][i]["u_name"]+'</th>';
                          
                                $teamDetail='</tr>';
                            }
                            $("#detail").html($teamDetail);
                        }
                    }else{
                        layer.msg(data["msg"]);
                    }
                },
                error:function(data) {
                    layer.msg('请求失败,请检查您的网络连接');
                }
            });
        }
  • 相关阅读:
    blob 下载功能和预览功能
    实现大文件上传
    element ui框架之Upload
    常用utils
    vue实现excel表格上传解析与导出
    理解script加载
    js处理10万条数据
    Shadow DOM
    20150625_Andriod_01_ListView1_条目显示
    20150624_Andriod _web_service_匹配
  • 原文地址:https://www.cnblogs.com/yszr/p/11505299.html
Copyright © 2011-2022 走看看