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"></i> 搜索</button>
<button name="" id="turnNull" class="btn btn-success" type="reset" onclick="tableClear()">
<i class="Hui-iconfont"></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('请求失败,请检查您的网络连接');
}
});
}