在几个字符后插入元素 [英] Insert element after several characters
本文介绍了在几个字符后插入元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Possible Duplicate:
Jquery or javascript to add one line break <br /> after x amount of characters in a <div>
我想在元素的内容中插入一个br
标记,五个字符.例如,从此:
I'd like to insert a br
tag five characters into the content of the element. For example, from this:
<p>qwertyuiopasdfghjklzxcvbnm</p>
对此:
<p>qwert<br />yuiopasdfghjklzxcvbnm</p>
我该如何使用jQuery?
How can I do this with jQuery?
推荐答案
用此函数简单地替换innerHTML(在document.ready()上触发):
Simply replace the innerHTML with this function (Fires on document.ready()):
$(document).ready(function() {
$('p').html($('p').html().substring(0,5)+'<br/>'+$('p').html().substring(5));
}
);
您可以在jfiddle上进行尝试: http://jsfiddle.net/KwpGr/1/
You can try it on jfiddle: http://jsfiddle.net/KwpGr/1/
这篇关于在几个字符后插入元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文