![](/img/trans.png)
[英]How can I change HTML tag color like h1, h2, p etc but keeping some h1, h2 tag unchanged?
[英]How can I cut a javascript array in half but to the nearest closing </p> or </h1> tag?
我可以將其切成兩半,但我不確定如何確保將下半部分切入下一個封閉塊級標記。
假Html:
<div class="content-item">
<h1>Title</h1>
<p>Pellentesque nec erat diam. Donec condimentum tortor nec tellus gravida uscipit</p>
<h1>Title</h1>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus</p>
</div>
到目前為止的Javascript:
var splitChar = " ";
var wordsSplit = $(".content-item").html().split(splitChar);
var wordsCount = wordsSplit.length;
var half = Math.floor(wordsCount / 2);
只需向前遍歷數組,直到您到達末尾或閉合塊為止
i = half;
while (!wordsSplit[i++].match(/<\//) && i < wordsSplit.length);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.