如何使用 ajax 实时搜索获取脚本文本框中的搜索值
How can i get the search value in script textbox using ajax live search?
我把我所有的代码都放在这里。当我单击文本框名称 = 动态文本框时,我从数据库 bt 中获取搜索值,我无法选择它,也无法在文本框上获取它。
.html:
<label class="input"> <i class="icon-append fa fa-user"></i>
<input type="text" required name="product_name" placeholder="product Name" style="margin-bottom:25px;">
<b class="tooltip tooltip-bottom-right">Needed to enter product Name</b> </label>
<lable style="margin-left:60px;"><b>Material Name</b></label>
<lable><b>Material Quantity</b></label>
<div id="TextBoxContainer"></div>
<input id="btnAdd" type="button" value="Add" style="margin-top:20px;margin-left:450px;width:40px;" />
<input id="btnGet" type="button" value="DONE" />
</br></br></br>
<input id="anotherTextbox" type="hidden" name="last" />
<input id="anotherTextbox1" type="hidden" name="first"/>
<input type="submit" name="submit" value="Register" class="btn btn-primary">
</form>
.js:
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","search1.php?q="+str,true);
xmlhttp.send();
}
</script>
<script>
$(function() {
$("#btnAdd").bind("click", function() {
var div = $("<div />");
div.html(GetDynamicTextBox(""));
$("#TextBoxContainer").append(div);
});
$("#btnGet").bind("click", function() {
var values =
$.map($("input[name=DynamicTextBox]"), function(el) {
return el.value
}).join(",'n");
$("#anotherTextbox").val(values);
});
$("#btnGet").bind("click", function() {
var values =
$.map($("input[name=DynamicTextBox1]"), function(el) {
return el.value
}).join(",'n");
$("#anotherTextbox1").val(values);
});
$("body").on("click", ".remove", function() {
$(this).closest("div").remove();
});
});
function GetDynamicTextBox(value) {
return '<input name = "DynamicTextBox" style="width:280px;margin-left:10px;" id="skills" onkeyup="showResult(this.value)" type="text" value = "' + value + '" /> ' + '<input style="width:280px;" name = "DynamicTextBox1" type="text" value = "' + value + '" /> ' +
'<span type="button" class="remove glyphicon glyphicon-remove"></span><div id="livesearch" style="width:280px;margin-left:10px;"></div>'
}
</script>
自动完成 使用户能够在键入时快速查找和选择预填充的值列表,从而利用搜索和筛选。
在此处查找链接https://jqueryui.com/autocomplete/#remote
点击view source
获取代码
相关文章:
- 搜索文本文件并附加到表中
- 在网站HTML页面上搜索文本
- 在JavaScript中搜索文本并获取其所有开始和结束索引
- 不显示 jsTree 搜索文本框
- “搜索”文本仅考虑表格中的最后一列
- 突出显示搜索文本引导程序表
- jQuery自动完成下拉列表中的粗体搜索文本字符
- 在文档中搜索文本以删除的文本超过找到它的标签
- JavaScript:获取搜索文本在正文上的滚动位置
- 使用JavaScript搜索文本
- jQuery在多个表中搜索文本,如果找到文本,则单击按钮
- 使用javascript从html中搜索文本
- 使用PowerShell在JavaScript网页上搜索文本字符串
- Javascript Regex exec 在向搜索文本添加属性/引号后冻结
- 具有搜索文本的功能,不能很好地处理标点符号/符号.Jquery/Jquery mobile.
- Javascript打开带有搜索文本的新窗口
- 谷歌语音识别搜索文本问题
- 我们可以使数据列表自动完成以搜索文本和值吗?
- 使搜索文本框输入值不区分大小写
- 在嵌套对象(例如 Backbone.js集合)中搜索文本