Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
Javascript jquery regex.replace不写入dom_Javascript_Jquery_Regex - Fatal编程技术网

Javascript jquery regex.replace不写入dom

Javascript jquery regex.replace不写入dom,javascript,jquery,regex,Javascript,Jquery,Regex,因此,我试图规范化/清理内容中的格式: <div class="content" contenteditable="true" data-placeholder="Type your entry"> <p>djsalk fjsadlkjf sadfjlsadkfj</p> <p> </p> <div>laksdfj asdlkasdf&nbsp;</div> </div&

因此,我试图规范化/清理内容中的格式:

<div class="content" contenteditable="true" data-placeholder="Type your entry">

    <p>djsalk fjsadlkjf sadfjlsadkfj</p>
    <p> </p>
    <div>laksdfj asdlkasdf&nbsp;</div>

</div>

djsalk fjsadlkjf sadfjlsadkfj

laksdfj asdlkasdf
使用以下js:

$('.content').html().replace(/\/div/g , '<p>');
$('.content').html().replace(/\/div/g , '</p>');
$('.content').html().replace('<p> </p>', '');
$('.content').html().replace(/\/div/g,);
$('.content').html().replace(/\/div/g,

); $('.content').html().replace('

','');

如果我在webinspector中手动运行每一行,它将返回固定字符串,但也不会将其应用于dom

我错过了什么


谢谢,replace函数会生成一个新字符串。您需要手动将该新值分配回dom,如下所示:

$('.content').html($('.content').html().replace(/\/div/g , '<p>'));
$('.content').html($('.content').html().replace(/\/div/g,'));

替换函数生成一个新字符串。您需要手动将该新值分配回dom,如下所示:

$('.content').html($('.content').html().replace(/\/div/g , '<p>'));
$('.content').html($('.content').html().replace(/\/div/g,'));

替换函数生成一个新字符串。您需要手动将该新值分配回dom,如下所示:

$('.content').html($('.content').html().replace(/\/div/g , '<p>'));
$('.content').html($('.content').html().replace(/\/div/g,'));

替换函数生成一个新字符串。您需要手动将该新值分配回dom,如下所示:

$('.content').html($('.content').html().replace(/\/div/g , '<p>'));
$('.content').html($('.content').html().replace(/\/div/g,'));

在javascript中,字符串是不可变的,jQuery的
.html()
返回一个字符串(不是对实际html元素的引用)。修改后必须设置html。使用jQuery执行此操作的一个好方法是调用:

$('.content').html(函数(i,html){
返回html.replace(/\/div/g,);
});

在javascript中,字符串是不可变的,jQuery的
.html()
返回一个字符串(不是对实际html元素的引用)。修改后必须设置html。使用jQuery执行此操作的一个好方法是调用:

$('.content').html(函数(i,html){
返回html.replace(/\/div/g,);
});

在javascript中,字符串是不可变的,jQuery的
.html()
返回一个字符串(不是对实际html元素的引用)。修改后必须设置html。使用jQuery执行此操作的一个好方法是调用:

$('.content').html(函数(i,html){
返回html.replace(/\/div/g,);
});

在javascript中,字符串是不可变的,jQuery的
.html()
返回一个字符串(不是对实际html元素的引用)。修改后必须设置html。使用jQuery执行此操作的一个好方法是调用:

$('.content').html(函数(i,html){
返回html.replace(/\/div/g,);
});

侧注:
replace
是本机JavaScript函数,不是来自jQuery。侧注:
replace
是本机JavaScript函数,不是来自jQuery。侧注:
replace
是本机JavaScript函数,不是来自jQuery。侧注:
replace
是本机JavaScript函数,不是从jQuery.com开始的,但是当我在小提琴中检查html时,它看起来仍然没有改变。同样出于好奇,'i'参数指的是什么?@Pirijan jqueryobject中元素的索引很有意义,但是当我在fiddle中检查html时,它似乎仍然没有改变。同样出于好奇,'i'参数指的是什么?@Pirijan jqueryobject中元素的索引很有意义,但是当我在fiddle中检查html时,它似乎仍然没有改变。同样出于好奇,'i'参数指的是什么?@Pirijan jqueryobject中元素的索引很有意义,但是当我在fiddle中检查html时,它似乎仍然没有改变。同样出于好奇,“i”参数指的是什么?@Pirijan索引jQuery对象中的元素