Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中使用数据库中的数据设置“读取更多”按钮_Php_Jquery_Laravel_Laravel 5 - Fatal编程技术网

如何在php中使用数据库中的数据设置“读取更多”按钮

如何在php中使用数据库中的数据设置“读取更多”按钮,php,jquery,laravel,laravel-5,Php,Jquery,Laravel,Laravel 5,实际上,我使用的是laravel框架。在这个框架中,我使用某些查询和方法从数据库中检索数据 下面是我的代码 <ul class="booking-list"> @foreach($aRooms as $aRoom) <li> .... <div class="comment more"> {{$aRoom->room_desc}} &l

实际上,我使用的是
laravel
框架。在这个框架中,我使用某些查询和方法从数据库中检索数据

下面是我的代码

<ul class="booking-list">
    @foreach($aRooms as $aRoom)
        <li>
        ....
            <div class="comment more">
                {{$aRoom->room_desc}}
            </div>
        ....
        </li>
    @endforeach
</ul>
谢谢,

我知道了

    @foreach($aRoom作为$aRoom)
  • .... @如果(strlen($aRoom->room_desc)>100) {{substr($aRoom->room_desc,0100)} 更多 {{substr($aRoom->room_desc,100,strlen($aRoom->room_desc))} 较少的 @否则 {{$aRoom->room_desc} @恩迪夫 ....
  • @endforeach
Javascript

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
// Hide the extra content initially, using JS so that if JS is disabled, no problemo:
            $('.read-more-content').addClass('hide_content')
            $('.read-more-show, .read-more-hide').removeClass('hide_content')

            // Set up the toggle effect:
            $('.read-more-show').on('click', function(e) {
              $(this).next('.read-more-content').removeClass('hide_content');
              $(this).addClass('hide_content');
              e.preventDefault();
            });

            // Changes contributed by @diego-rzg
            $('.read-more-hide').on('click', function(e) {
              var p = $(this).parent('.read-more-content');
              p.addClass('hide_content');
              p.prev('.read-more-show').removeClass('hide_content'); // Hide only the preceding "Read More"
              e.preventDefault();
            });
</script>

//最初使用JS隐藏额外内容,以便在禁用JS时不会出现问题:
$('.read more content').addClass('隐藏内容')
$('.read more show,.read more hide').removeClass('hide_content'))
//设置切换效果:
$('.read more show')。关于('单击',函数(e){
$(this).next('.readmore content').removeClass('hide_content');
$(this.addClass('hide_content');
e、 预防默认值();
});
//@diego rzg提供的变更
$('.read more hide')。在('click',函数(e)上{
var p=$(this.parent('.read more content');
p、 addClass(“隐藏内容”);
p、 prev('.read more show').removeClass('hide_content');//仅隐藏前面的“read more”
e、 预防默认值();
});
为此,我在css文件中使用了一些样式

<style type="text/css">
    .read-more-show{
      cursor:pointer;
      color: #ed8323;
    }
    .read-more-hide{
      cursor:pointer;
      color: #ed8323;
    }

    .hide_content{
      display: none;
    }
</style>

.阅读更多节目{
光标:指针;
颜色:#ed8323;
}
.阅读更多隐藏{
光标:指针;
颜色:#ed8323;
}
.隐藏内容{
显示:无;
}

您也可以在不使用javascript的情况下执行这些操作

    <?php 

 $longString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";


        echo readMoreHelper($longString);


        function readMoreHelper($story_desc, $chars = 100) {
            $story_desc = substr($story_desc,0,$chars);  
            $story_desc = substr($story_desc,0,strrpos($story_desc,' '));  
            $story_desc = $story_desc." <a href='#'>Read More...</a>";  
            return $story_desc;  
        } 

     ?> 


                                    **// OR**
<?php

 $story_desc = substr($longString,0,100);  
 $story_desc = substr($story_desc,0,strrpos($story_desc,' '));  
 echo $story_desc."<a href='#'>Read More...</a>";

?>

**//或**
注意://在代码中,必须使用变量而不是$longString

<style type="text/css">
    .read-more-show{
      cursor:pointer;
      color: #ed8323;
    }
    .read-more-hide{
      cursor:pointer;
      color: #ed8323;
    }

    .hide_content{
      display: none;
    }
</style>
    <?php 

 $longString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";


        echo readMoreHelper($longString);


        function readMoreHelper($story_desc, $chars = 100) {
            $story_desc = substr($story_desc,0,$chars);  
            $story_desc = substr($story_desc,0,strrpos($story_desc,' '));  
            $story_desc = $story_desc." <a href='#'>Read More...</a>";  
            return $story_desc;  
        } 

     ?> 


                                    **// OR**
<?php

 $story_desc = substr($longString,0,100);  
 $story_desc = substr($story_desc,0,strrpos($story_desc,' '));  
 echo $story_desc."<a href='#'>Read More...</a>";

?>