自动完成搜索框获取HTML内容而不是文本

时间:2015-06-02 05:49:11

标签: javascript php jquery

我在php的搜索框中使用jquery自动完成功能。 我通过php获取值到自动完成插件。

当我开始输入并从下拉列表中选择一些结果或点击某些结果时,搜索框会以html格式而不是纯文本形式获得结果,例如

<a href="#/results" class="searchres" onclick="navigate()" style="color:#696969;text-decoration:none;"><img src=images/pdf-d.png class="icons" /><div class="results" style="color:#696969;text-decoration:none;">my pro</div><span style="color:#696969;text-decoration:none;" class="author">My space in</span></a>

当我从下拉列表中选择结果时,我想要div .results“我的专业人士”中的文字。我怎么能得到它?

PHP:

<?php
require_once "config.php";
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select file_name,img_url,captions from completer";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
    $fname = $rs['file_name'];
    $iurl = $rs ['img_url'];
    $caption = $rs ['captions'];
    echo '<a href="#/results" class="searchres" onclick="navigate()" style="color:#696969;text-decoration:none;"><img src='.$iurl.' class="icons" /><div class="results" style="color:#696969;text-decoration:none;">'."$fname".'</div><span style="color:#696969;text-decoration:none;" class="author">'.$caption.'</span></a>'."\n";
}
?>

我还附上了图片的外观和样子。需要帮助解决这个问题。

现在的样子。

enter image description here

它应该是这样的样子

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个:

<?php
    (everything in php)
    then...
    $var_your_var = "<a blah your a tag><img/></a>";
?>
<html>
<body>
    <?php echo $var_your_var ?>
</body>
</html>

或者你应该将html放在你的html中并回显你要放在html标签中的文本。使用javascript / ajax将输入发送到php并相应地调整html。