搜索框动态数据点击事件,动态获取数据
<button type="button" class="btn_reach" onclick="disserach_click()">搜索</button> 搜索框模板 <script id="disREACHE" type="text/html"> <div class="pet_list_one_info_ico heardlndex"> <img class="heardImg" src="../../Static/Img/小丸子呀.jpeg" alt=""> </div> <div class="pet_list_one_info_name"> <label class="heard_lab">昵称:</label> <label class="heard_lab lable_name">{{data.username}}</label><br> <label class="heard_lab">手机号:</label><label class="heard_lab lable_name">{{data.mobile}}</label><br> </div> </script> function disserach_click() { var username = $(".reach").val();// 获取数据 $.ajax({ type: "GET", url: http + 'UserInfo?username=' + username, //get传参方法 contentType: 'application/json', dataType: "json", success: function (data) { if (data.state == 1) { var result = template("disREACHE", data) $("#indexs").html(""); //清空缓存 $("#indexs").append(result); } else { alert('接口获取错误:' + data.info); } } }); } 当打开界面就需要展示数据时候,才需要初始化。