我試圖創建將啓用或禁用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