我在变量cleanHTML 中有多个完整的 html 代码,我需要从文本中删除特定标签。
let cleanHTML = document.documentElement.outerHTML
Run Code Online (Sandbox Code Playgroud)
这个:
<span class="remove-me">please</span>
<span class="remove-me">me too</span>
<span class="remove-me">and me</span>
Run Code Online (Sandbox Code Playgroud)
对此:
please
me too
and me
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样做:
var list = cleanHTML.getElementsByClassName("remove-me");
var i;
for (i = 0; i < list.length; i++) {
list[i] = list[i].innerHTML;
}
Run Code Online (Sandbox Code Playgroud)
但是我从 React cleanHTML.getElementsByClassName 中得到错误不是函数
知道如何以 React 喜欢的方式做到这一点吗?
我有组件方法更新的可编辑元素,但我也有json导入,我想更新元素我的父方法.我可以更新模型,但可编辑元素不会绑定它.如果我将内容插入组件模板,它将绑定更新的模型,但后来我无法真正编辑它.
这是我的例子:https://jsfiddle.net/kuwf9auc/1/
Vue.component('editable', {
template: '<div contenteditable="true" @input="update"></div>', /* if i insert {{content}} into this div, it wil update, but editing behave weird */
props: ['content'],
mounted: function () {
this.$el.innerText = this.content;
},
methods: {
update: function (event) {
console.log(this.content);
console.log(event.target.innerText);
this.$emit('update', event.target.innerText);
}
}
})
var app = new Vue({
el: '#myapp',
data: {
herobanner: {
headline: 'I can be edited by typing, but not updated with JSON upload.'
}
},
methods: {
uploadJSON: function (event) …Run Code Online (Sandbox Code Playgroud)