剪切HTML内容并保持格式?
问题描述:
$str = "<div>blahblahblah<b>foofoo</b><i>barbar</i></div>";
I separate two part
1-presentation_text
2-full content when click on read more.
$presentation = substr($str,0,23);
<div>blahblahblah<b>foo
$detail = substr($str,23);
foo</b><i>barbar</i></div>
How Can I keep the format when it display in presentation block and detail block? I mean
in presentation block should be:
blahblahblahfoo /* foo have bold here*/
in detail block
foobarbar /* foo have bold too*/
$ str =“&lt; div&gt; blahblahblah&lt; b&gt; foofoo&lt; / b&gt;&lt; i&gt; barbar&lt; / i&gt;&lt; / div&gt;“;
code> pre>
我将两部分分开 p>
1-presentation_text
2-完全内容,点击阅读更多。
$ presentation = substr($ str,0,23);
&lt; div&gt; blahblahblah&lt; b&gt; foo
$ detail = substr($ str,23 );
foo&lt; / b&gt;&lt; i&gt; barbar&lt; / i&gt;&lt; / div&gt;
code> pre>
如何在演示文稿块中显示格式时保留格式 和详细信息块?
我的意思是 p>
在演示文稿块中应该是: p>
blahblahblah foo b> / * foo这里有加粗 * / p>
in detail block
p>
foo b> barbar i> / * foo也加粗* / p>
div>
答
Much easier to do it client-side:
CSS
.presentation {
width: 200px;
height: 20px;
overflow: hidden;
}
.detail {
width: auto;
height: auto;
}
Javascript
$(function(){
$('.presentation').live('click', function(){
$(this).attr('class', 'detail');
});
$('.detail').live('click', function(){
$(this).attr('class', 'presentation');
});
});
HTML
<div class="presentation">
<div>blahblahblah<b>foofoo</b><i>barbar</i></div>
</div>
Working example: http://jsfiddle.net/fznWf/1/