我有这段代码,它是 CraigStuntz 的内容可编辑占位符。
我的问题是我应该把这段代码放在哪里,这样所有div
包含的内容contenteditable
都会生效。
我试图把它放在下面,app.controller('myCtrl', function(){});
但它只适用于直接作用域。没有嵌套范围有效。
angular.element(document.querySelectorAll('div[contenteditable]')).bind('change keydown keypress input', function() {
if (this.textContent) {
this.setAttribute('data-contenteditable-placeholder', 'true');
}
else {
this.removeAttribute('data-contenteditable-placeholder');
}
});