jQueryの:のnodeValue変更のための鑑賞
-
20-09-2019 - |
質問
私はのcontentEditableで編集しています要素ののnodeValueの変更を監視します。基本的に、私はのnodeValueの変化に機能を実行したい。
私はこの記事を見つけました: http://james.padolsey.com/javascript/monitoring-dom-properties/ >
私が欲しいもののためにプラグインを持っているようだ。
ここでは、時計のプラグインです。
jQuery.fn.watch = function( id, fn ) {
return this.each(function(){
var self = this;
var oldVal = self[id];
$(self).data(
'watch_timer',
setInterval(function(){
if (self[id] !== oldVal) {
fn.call(self, id, oldVal, self[id]);
oldVal = self[id];
}
}, 100)
);
});
return self;
};
例として、私はこのような入力の値を見ることができます:
$('#input').watch('value', function(propName, oldVal, newVal){
$("#text").text(newVal);
});
しかし、ではないのcontentEditableののnodeValue(そのテキストコンテンツ):
$('#ce').watch('nodeValue', function(propName, oldVal, newVal){
$("#text").text(newVal);
});
ここでは実際の例です。
誰でものnodeValueで動作するように時計の方法を適応させる方法を知っています。ありがとう!
解決
この単純ではないか。
$('#ce')
.bind('change keyup',
function() {
$('#text')
.text($(this).text());
}
);
入力として
$('#input')
.bind('change keyup',
function() {
$('#text')
.text($(this).val());
}
);
所属していません StackOverflow