用于PHP脚本内自动完成的jquery脚本在<form>标签</form>中不起作用

时间:2012-12-14 23:27:53

标签: php jquery html5

我正在为php脚本中的输入文本框执行自动完成功能。这是javascript。一切正常...... search.php只是填入div选项。这是真正的问题。当我将输入文本框放在标记内时,显示自动完成选项的div无法在页面上呈现。我可以将div放在页面的任何位置,只要页面上没有任何位置,它就可以工作。

<script type="text/javascript">
$(document).ready(function(){
$(".search").keyup(function()
{
var searchbox = $(this).val();
var dataString = 'searchword='+ searchbox;
if(clan_id=='')
{
}
else
{
$.ajax({
type: "POST",
url: "search.php",
data: dataString,
cache: false,
success: function(html)
{
$("#display").html(html).show();
}
});
}return false;
});
});
jQuery(function($){
$("clan_id").Watermark("Search");
});
</script>

search.php正在返回此代码:

echo "<div class=\"display_box\" align=\"left\" onclick=\"document.getElementById  ('clan_id').value =' $final_clan_id '\">\n";
echo "<img src=\" $img \" style=\"width:25px; float:left; margin-right:6px\" />$final_clan_name  <br/></div>\n";

autocomplete适用于此:

echo "<input type \"text\" id=\"clan_id\">\n";

自动完成功能失败了:

echo "<form name ='showClan' method='post' action='" .  htmlentities($_SERVER['PHP_SELF']) . "'>\n";
echo "<input type \"text\" id=\"clan_id\">\n";
echo "</form>";

1 个答案:

答案 0 :(得分:0)

在审核和测试代码时,有几件事情很突出:

1)您的搜索字段没有您的jQuery函数正在查找的“搜索”类。

2)您的类型属性在两个示例中都缺少等号。

<input class="search" type="text" id="clan_id">

这是一个包含搜索字段和显示div的工作示例:

http://jsfiddle.net/hansvedo/zhQse/

相关问题