从jquery的搜索结果中添加内容搜索结果、内容、jquery

2023-09-10 14:59:57 作者:颓废的少年@

我用这清凉的脚本 http://qpoit.com/marcofolio_demo/apple_search/ 然而,当我点击一个搜索结果,我希望它被添加为HTML内容的ID,我会用等。我知道这是用$(#displayContent)完成的HTML(数据)。但是,我需要的搜索结果,我点击是,而不是发现所有的结果的内容。请帮忙

I am using this cool script http://qpoit.com/marcofolio_demo/apple_search/ however when I click on a search result, I want it to be added as html content to an id which I will use like . I know this is done with $("#displayContent").html(data); however I need the content of search result that I clicked on to be and not all the results found. Please help

推荐答案

搜索的rpc.php文件,包含了函数,该函数生成搜索的输出。 在第29行,更改内容,以一个JavaScript函数,它这是否对你的工作。

The rpc.php-file of the search, contains the function, which generates the output of the search. In line 29, change the content to a JavaScript-function, which does this work for you.

// Used in line 29 in rpc.php
echo '<a href="'.$result->url.'">';

// Change it to something like
echo '<a onclick="applyContent('.$result->url.')">'

在这之后,回到(您使用的是苹果的搜索或文件)中的index.html,确保jQuery的加载,并添加这样的:

After that, head back to the index.html (or the file in which you are using the apple-search), make sure jQuery is loaded and add something like this:

<script type="text/javascript">
// Use the same function name, as in the php-file
function applyContent (resultURL) {
    // Use jQuerys get-function to get the content of the file you've found in the search
    $.get(resultURL, function(data) {
        // Change '#finalResult' to the css-selector, of the element, which should contain the result at the end
        $('#finalResult').html(data);
    });
}
</script>

一旦你点击一个搜索结果,就应该让#finalResult的内容,或任何元素,您选择。

Once you click on a search-result, it should make it the content of #finalResult, or whatever element you choose.