答案 0 :(得分:0)
只需使用一些简单的步骤:为要包装的字符数设置8
var p = $('p'), string = p.text();
if (string.length > 8) {
var stringToWrap = string.substring(0, 8);
p.html(string.replace(stringToWrap, '<span>'+ stringToWrap +'</span>'));
}
&#13;
span {
font-weight: bold;
color: red;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>日本刀日本刀日本刀日本刀</p>
&#13;