我試圖實現顯示多個divs中的更多鏈接(如這裏http://www.gutscheinpony.de/outletcity.html,你點擊細節,你會得到隱藏的div) 但是我通過PHP和分類達到50個領域喜歡在這些方面,我需要個人ID,這樣我可以分開打開每個DIV。問題是我需要通過php給每個div一個變量id!但我卡住了。你可以在這裏看到問題http://cloud0815.joloshop.com/shops/1822direkt(點擊兩個「顯示更多」文本),只有第一個會打開!!!)顯示更多在一個div與php和css
回答
如果你使用jQuery,你不需要給每個div一個單獨的ID。您可以爲每個「顯示更多」鏈接提供一個類似「show-more」的鏈接。然後,將鏈接綁定到點擊處理程序。 $(this)變量告訴你50個鏈接中的哪個被點擊了。你如何選擇包含隱藏的文本的div取決於您的標記,但這裏是你可以做什麼的例子:
PHP:
/* Inside a loop */
<?php
$full_text = get_the_content();
$period_pos = strpos($full_text, ".");
$excerpt = substr($full_text, 0, $period_pos+1); // Get the first line, assuming that a line ends with a period.
$rest = substr($full_text, $period_pos+1); // Get the rest of the text
?>
<div class="excerpt">
<?php echo $excerpt; ?>
</div>
<div class="rest">
<?php echo $rest; ?>
</div>
<div class="show-more-div">
<a href="#" class="show-more">Show more</a>
</div>
的jQuery:
$(document).ready(function(){
$(".show-more").click(function(){
$(this).parent().prev().slideDown();
});
});
我也可以代替20個字符選擇第一行的內容嗎? – user2605258
當然,看我的編輯。 – PhoenixWing156
謝謝,最後一個。我得到的內容通過PHP顯示,我在哪裏把代碼<?php the_content(); ?> – user2605258
- 1. 在CSS中如何顯示多個div?
- 2. 刷新一個與PHP顯示的div
- 3. Css hover div顯示另一個div
- 4. Jquery顯示更多div和顯示更少div
- 5. css - 在另一個之上顯示div
- 6. CSS技巧來顯示多個div
- 7. 顯示更多jquery與兩個div一起工作
- 8. 爲一個div回顯多個css類
- 9. 顯示/隱藏多個div與多選
- 10. 使用CSS(導航菜單)在同一行顯示多個div
- 11. 顯示更多功能與css
- 12. 顯示一個div和側
- 13. CSS,顯示內聯和三個div的
- 14. 在桌面上顯示div並在CSS上顯示另一個div
- 15. 顯示和隱藏一個div元素,並在CSS
- 16. jQuery顯示更多/顯示更少切換高度div div
- 17. 隱藏圖像和顯示iframe,但在一個div與多個類
- 18. Css在行和列中顯示div
- 19. 顯示更多按鈕與PHP的Mysql
- 20. CSS - 在一行div顯示圖像
- 21. 一個接一個地顯示div,另一個顯示div
- 22. CSS懸停更改多個div的風格與同一父母
- 23. 顯示每個div都在一個DIV總量與jQuery的
- 24. 顯示並在一個div
- 25. PHP/CSS - 防止div顯示如果
- 26. 顯示/隱藏一個div PHP的WordPress
- 27. jquery顯示一個div div
- 28. 自動顯示和隱藏多個div
- 29. foreach和hide /顯示多個div
- 30. HTML和JavaScript顯示多個div的
的方式做好了充足這裏有:http://stackoverflow.com/questions/2717181/cut-text-after-x-amount-of-characters,並通過http://stackoverflow.com/search?q=truncate+string+php –
謝謝,但是,那不是問題。我想在一行之後剪切文本並且有一個(鏈接)更多......並且其他行應滑動打開... – user2605258