gpt4 book ai didi

javascript - 输入后,在 db 中搜索字符串

转载 作者:行者123 更新时间:2023-11-28 00:38:16 24 4
gpt4 key购买 nike

我有这个代码:

<body>
Please make your selection:
<div id="div1">
<tr>
<td>
<input type="button" value="Insert" onclick="form.html" />
</td>
<td>
<input type="button" value="View" onclick="window.location='view-master.php';" />
</td>
<td>
<input type="button" value="Edit" onclick="edit.html" />
</td>
<td>
<input type="button" value="Search" onclick="showsearchform()" />
</td>
</tr>
</div>
</body>

然后是 JS:

<script type="text/javascript">
function showsearchform()
{
var tr = document.createElement("tr");
var td = document.createElement("td");
var label = document.createElement("label");
label.id = "label1";
label.value = "Surname";

var input = document.createElement("input");
tr.appendChild(td);
td.appendChild(label);
td.appendChild(input);

var element = document.getElementById("div1");
element.appendChild(tr);

$('#input').keyup(function (e) {
var str = $('#search').val();
var url = "search.php";
if (e.keyCode == 13) {
location.href = url;
}
});
}
</script>

当我点击搜索时,我得到了收件箱,但我现在想做的是,当我在框中输入姓氏并按 Enter 键时,我想连接到数据库并搜索这个姓氏

我可以做数据库的事情,只是不确定 JS 和 Jquery

最佳答案

html

  <input type="text" name="txt" onkeypress="Search" />

JavaScript

<script>
function Search(e){
if(e.keyCode === 13){// enter key value is 13


**// Your ajax request write here , and in server side you can
**check corresponding results in database and return if data is present and take it as ajax replay****
}

return false;
}
</script>

关于javascript - 输入后,在 db 中搜索字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28235586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com