나는 Craig Stuntz's javascript contenteditable placeholder을 기반으로 한 자리 표시자를 사용하여 contenteditable 지시어를 사용합니다. DIV는 TextContent가있을 경우 숨기기 자리 다른 쇼 자리 div 텍스트를 angularjs 지시어로 전달
- 검사를 수행하지만 이미 언급 한 문제가의 contentEditable 다음 자리를
을 숨기기에 사용자 초점 크레이그 스턴트에 의해
If you update the div text in JavaScript (instead of just typing into the div on the page), no events are fired, and you must let the plugin know that you've changed the contents by triggering the change event.
는 어디서,981을 넣어 아무 생각이 없다그리고 javascript에서 div 텍스트가 비어 있거나 비어 있지 않은지 어떻게 알 수 있습니까?
아래 코드
app.directive("contenteditable", function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
// view -> model
element.bind('input', function() {
scope.$apply(function() {
ctrl.$setViewValue(element.text());
});
if (this.textContent) {
this.setAttribute('data-contenteditable-placeholder', 'true');
console.log(this);
} else {
this.removeAttribute('data-contenteditable-placeholder');
}
});
// model -> view
//ctrl.$render = function() {
// element.text(ctrl.$viewValue);
//};
//ctrl.$setViewValue(element.text());
}
}
});
CSS
*[data-placeholder]:not(:focus):not([data-contenteditable-placeholder])::before {
content: attr(data-placeholder);
margin-left: 2px;
color: #b3b3b3;
}
div[contenteditable]:focus{
outline: none;
}
언제든지이 솔루션을 게시 할 수 있습니까? – chris