是否可以使用jquery和split方法跳过html标签?
我正在使用split
将javascript生成的文本插入到html文本中,但是我需要跳过像html标签这样的部分,所以在搜索了很多之后,我发现了这个:
var = var.replace(//g, '\n');
问题是它不会跳过标记或该变量中指定的任何内容,它实际上用空格替换标记。
我需要实现的是,例如:
random javascript
my text
--- New text that needs to be inserted ---
目前发生了什么:
my text
--- New text that needs to be inserted ---
正如你所看到的,第一个标签(javascript)没有被滑落,它们被剥离了。
我应该使用什么方法代替替换?
将javascript生成的文本插入到html文本中
我需要实现的是,例如:
my text
--- New text that > needs to be inserted ---
尝试使用document.createTextNode()
.insertAfter()
var text = document.createTextNode("--- New text that needs to be inserted ---"); $(text).insertAfter("p:contains(my text)")
my text