核桃说笔记

点击展开看更多内容的效果:
<div class="ht_div14">
<div class="ht_div15">
<p class="ht_p19">
<img src="{$answerx['author_avartar']}" class="ht_img17" />
<img src="{SITE_URL}static/pc/img/sy14.png" class="ht_img18" style="display:none" />
</p>

<div class="ht_div16">
<div class="ht_div17">
<p class="ht_p20">{$answerx['author']}</p>
<!--<p class="ht_p21"></p>
<p class="ht_p22">{$answerx['author_groupname']}</p>-->
</div>

<p class="ht_p23">
<span>{$answerx['time']}</span>
</p>
</div>
</div>

<div class="ht_p25">
<div class="ht_p25_yincang">
部分内容。。。。。。
</div>
<p class="ht_p46">
<span>展开全部</span>
<img src="{SITE_URL}static/pc/img/sy07.png" />
</p>
</div>


</div>

<script type="text/javascript"> /*点击展开全部效果*/ $(function() { $(".ht_div14").each(function() { var hh = $(this).find(".ht_p25").height(); var zk = $(this).find(".ht_p46").html(); if(hh > 400&&zk) { $(this).find(".ht_p25").css("max-height", "400px"); $(this).find(".ht_p25 .ht_p46").show(); } }) }) $(".ht_p46").on("click", function() { $(this).hide(); $(this).parents(".ht_p25").css("max-height", "none"); }) </script>

 

搜索关键词高亮显示:公共方法

//srl 7-23 搜索覌點,覌點高亮变色修改
function highlightDesc($content, $words, $highlightcolor = 'red') {
    $wordlist = explode ( " ", $words );
    foreach ( $wordlist as $hightlightword ) {
        if (strlen ( $content ) < 1 || strlen ( $hightlightword ) < 1) {
            return $content;
        }
        $content = preg_replace ( "/$hightlightword/is", "<font color=#D5615B><strong>\\0</strong></font>", $content );
    }
    return $content;
}

使用方法:控制器方法:使用上面方法进行高亮显示

    //关键词搜索
    function get_by_likename($word, $start = 0, $limit = 6) {
        $topiclist = array ();

        $query = $this->db->query ( "SELECT * FROM " . $this->db->dbprefix . "answer WHERE content like '%$word%' order by id desc LIMIT $start,$limit" );
// var_dump($query->result_array ());die;
        foreach ( $query->result_array () as $topic ) {
            $topic ['title'] = checkwordsglobal ( $topic ['title'] );
            $topic ['describtion'] = checkwordsglobal ( $topic ['content'] );
            $topic ['title'] = highlightDesc ( $topic ['title'], $word );
$topic ['describtion'] = highlightDesc (  strip_tags ( $topic ['content'] ), $word );$topiclist [] = $topic;
        }

        return $topiclist;
    }
剥去字符串中的 HTML 标签:
strip_tags

页面中使用topiclist 函数遍历显示在页面中即可

 

posted @ 2019-04-19 15:43  御世制人  阅读(252)  评论(0编辑  收藏  举报