中定義的某個點開始。我有一個包含一個div的所有文字,如:Collapsable div,但是從變量
<div class="text-container">
<p>
Though we welcome the idea of a smaller connector, we're miffed that Apple couldn't just adopt the semi-industry standard of Micro-USB. That would make things easier for smartphone users across the globe. Yet, even so, the smaller connector may be a smart move for the future. The 30-pin connector has been around since 2003, long before the iPhone even existed: frankly, it's a dust magnet. A smaller connector helps shave extra space to achieve a smaller phone with perhaps a bigger battery. The new connector cable will mainly be used for syncing and charging by most people who own an Apple TV or Bluetooth/AirPlay accessories.
</p>
</div>
而且我想創造這樣的事情:
<div class="text-container">
<p>
Though we welcome the idea of a smaller connector...<a href="some-javascript-to-show-more">[show more]</a>
</p>
</div>
我想我應該得到的div的所有內容,然後找到首先例如50個字符並放置一個鏈接,並將所有其他文本放入一些將被隱藏的div中,並在點擊該鏈接後顯示其他內容。
它應該是類似於切換的,如果它展開,則將文本從[show more]更改爲[show less],反之亦然。
任何建議如何使用普通的javascript和jquery本身並且沒有其他jQuery插件來實現這一點?
你已經回答了你的問題:「我想我應該得到的div的所有內容,然後找到的第一個如50個字符,並把有聯繫和所有其他文本放在一些將被隱藏的div中,點擊鏈接後,其他的東西就會顯示出來。「 – ankur
是的,但我不是很好的JavaScript和jQuery,我可以自己解決它。我需要一點點幫助,如何解決這個問題。我相信未來也會有其他人從中受益。 – Derfder