我试图创建将启用或禁用contenteditable
但是对于所有<div>
的我得到contentEditable
不是功能的功能按钮,任何人都知道为什么吗?遗漏的类型错误:CONTENTEDITABLE不是一个函数
function contentEditable() {
var x = document.getElementsByClassName("editable");
if ($(this).attr("contentEditable") == "true") {
console.log=(hello);
x.setAttribute('contentEditable', 'true');
button.innerHTML = "Enable content of p to be editable!";
} else {
x.setAttribute('contentEditable', 'false');
button.innerHTML = "Disable content of p to be editable!";
}
}
<button onclick="contentEditable(this);" id="contentEdit" class="btn btn-primary form-control margin">Edit Text</button>
您的脚本可能未运行,或者在contentEditable()被定义之前失败。我们需要一个http://jsfiddle.net/例子来看看到底发生了什么。 – Cauterite
事实上,代码的顺序在这里很重要。另外,getElementsByCLassName返回一个活动节点列表,因此您需要访问第一个节点x [0]。 'console.log =(helllo);'是一个错字。 – Shilly
它可能是属性'''contentEditable'''的初始值不是'''“true”'''但是''''继承“'''? – daniegarcia254