Php 可选择/可单击的值ajax列表中的表值
我目前正在努力使我的AJAX搜索查询尽可能的体面 我找到了很多不同的方法,但是我想要这个,因为它是最简单的:Php 可选择/可单击的值ajax列表中的表值,php,jquery,html,ajax,Php,Jquery,Html,Ajax,我目前正在努力使我的AJAX搜索查询尽可能的体面 我找到了很多不同的方法,但是我想要这个,因为它是最简单的: $country_name = str_replace($_POST['keyword'], '<b>'.$_POST['keyword'].'</b>', $rs['country_name']); echo '<li onclick="set_item(\''.str_replace("'", "\'", $rs['country_name']).'\
$country_name = str_replace($_POST['keyword'], '<b>'.$_POST['keyword'].'</b>', $rs['country_name']);
echo '<li onclick="set_item(\''.str_replace("'", "\'", $rs['country_name']).'\')">'.$country_name.'</li>';
<form>
<div class="label_div">Type a keyword : </div>
<div class="input_container">
<input type="text" id="testInput" onkeyup="autocomplet()">
<ul id="country_list_id"></ul>
</div>
</form>
JS
但是我改变了很多代码
// set_item : this function will be executed when we select an item
function setvalue(item)
$(".item").click(function()
{
$(".testInput").val(item));
$('.showSearch').hide();
})
})
我希望它将值设置到jQuery提供列表的输入中
echo("<a id="item"onclick="setvalue()">$rows[1]$rows[2]$rows[3]</a>");;
echo(“$rows[1]$rows[2]$rows[3]”);;
或者我想要这个代码
country_name = str_replace($_POST['keyword'], '<b>'.$_POST['keyword'].'</b>', $rs['country_name']);
echo '<li onclick="set_item(\''.str_replace("'", "\'", $rs['country_name']).'\')">'.$country_name.'</li>';
country\u name=str\u replace($\u POST['keyword'],'.$\u POST['keyword'],$rs['country\u name']);
echo'。$country\u name. ”;
更容易理解。因为目前,如果我想从一个表中实现它,这是非常混乱的。如果有人对如何编写代码有任何建议。非常感谢 你的ajax调用的代码在哪里?我忘了添加它,因为它是通用的。在你的HTML中没有
id=country\u id
。有,但我没有告诉它。我需要知道的是country\u name=str\u replace($\u POST['keyword'],'.$\u POST['keyword'],$rs['country\u name']);echo'id=country\u id
。有,但我没有告诉它,我需要知道的是country\u name=str\u replace($\u POST['keyword'],'.$\u POST['keyword'],$rs['country\u name']);echo'echo("<a id="item"onclick="setvalue()">$rows[1]$rows[2]$rows[3]</a>");;
country_name = str_replace($_POST['keyword'], '<b>'.$_POST['keyword'].'</b>', $rs['country_name']);
echo '<li onclick="set_item(\''.str_replace("'", "\'", $rs['country_name']).'\')">'.$country_name.'</li>';