Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqueryselect<;br>;标记并在其周围环绕空格_Jquery_Replace - Fatal编程技术网

jqueryselect<;br>;标记并在其周围环绕空格

jqueryselect<;br>;标记并在其周围环绕空格,jquery,replace,Jquery,Replace,例如,我有以下标记: Test text<br> test2 text 测试文本 测试2文本 它的内部需要在前后都有一个空间。像这样 " <br> " “” 因此,我可以拆分整个文本,得到如下完整列表: Test text <br> test2 text 测试 文本 测试2 文本 我使用以下代码进行拆分: var words = text.split(" "); // console.log("words:" +

例如,我有以下标记:

Test text<br>
test2 text
测试文本
测试2文本

它的内部需要在前后都有一个空间。像这样

" <br> " 

因此,我可以拆分整个文本,得到如下完整列表:

Test
text
<br>
test2
text
测试
文本

测试2 文本
我使用以下代码进行拆分:

var words = text.split(" ");
    //            console.log("words:" + words);
for ( var i = 0, l = words.length; i<l; ++i ) {
    //  console.log(i +": "+words[i] );
}
var words=text.split(“”);
//console.log(“文字:”+文字);
对于(var i=0,l=words.length;i
$(“#artikel”).html(函数(索引,oldhtml){
返回oldhtml.replace(/\/gi,“
”); });
html


您能具体说明什么是“不工作”吗?您应该使用
而不是空格
// Replace all "<br>" to " <br> "             
$("#artikel br").each(function(){
   alert($(this).index()));
});
$("#artikel").html(function(index, oldhtml){
    return oldhtml.replace(/\<br\>/gi, "&nbsp;<br>&nbsp;"); 
});