【问题标题】:jQuery quickSearch / Live SearchjQuery 快速搜索/实时搜索
【发布时间】:2015-03-20 20:25:38
【问题描述】:

我成功地将jQuery quickSearch(示例#1 更改)实现到了 WordPress 模板中,但为了使其真正完美,我需要帮助来实现我想要的我必须调整 jQuery 部分,但事实并非如此我的强项。

在我的 header.php 模板中,我有:

<?php if(is_post_type_archive('books')){
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript" src="<?php bloginfo('template_directory')?>/js/jquery.quicksearch.js"></script>
    <script type="text/javascript">
$(function () {
$('input#id_search').quicksearch('div#booklist div.cover');

        });
    </script>
<?php
}
?>

在我的 WordPress 模板中(省略查询):

<form action="#" id="searchform"><div><input autocomplete="off" type="text" name="s" class="search" id="id_search" onblur="if (this.value == '') {this.value = 'enter title of the book you are looking for...';}" onfocus="if (this.value == 'enter title of the book you are looking for...') {this.value = '';}" value="enter title of the book you are looking for..."/></div></form>

<div id="booklist">

<h4>Series Name</h4>

<div class="cover"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php echo $ftimg; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="133" height="200" /></a>
<?php
echo "<br>";
the_title();
?>
</div>

<h4>Series Name #2</h4>

<div class="cover"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php echo $ftimg; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="133" height="200" /></a>
<?php
echo "<br>";
the_title();
?>
</div>


and so on....

</div>

当我现在通过输入书名来使用搜索时,不仅这本书会显示为结果,而且所有 h4 标题也会显示。 我想要的视觉结果是只有书的 h4 标题(即书所属系列的名称)和书本身保留,所有其他 h4 标题“消失”,就像其他书与查询不匹配一样做。

【问题讨论】:

标签: jquery wordpress search quick-search


【解决方案1】:

试试下面的代码,让我知道输出。

    $(function () {
    $('input#id_search').quicksearch('div#booklist div.cover',{
        'show': function () {
            $(this).addClass('show');
        }
    });

    if($('div#booklist div.cover').hasClass('show') && $.trim($('#txtEmail').val()).length>0){
        $('.show').prev('h4').css('display','block !important');
        $('h4').css('display','none');
    }

    });

注意:未经测试

【讨论】:

  • 感谢您的帮助。不幸的是,即使在我在搜索字段中输入任何内容之前,所有 h4 标题都被隐藏/不显示。
  • 你能再试一次吗?我可以看看你的网站吗?
  • 可能有一些错误..如果我可以查看您的网站,它将帮助我检测到这个错误..
  • 网站正在开发中,但我整理了一个测试页面,其中仅包含查询:crocodesigns.com/jquery_test.php。此测试页使用您的最新代码。
  • 你能再试一次吗?更改上面链接中的代码,以便我也可以看到结果。麻烦你了:)
猜你喜欢
  • 1970-01-01
  • 2018-10-10
  • 1970-01-01
  • 2023-04-06
  • 2010-11-22
  • 2011-05-11
  • 2021-01-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多