我将使用CKeditor允许用户在登录后直接内联编辑页面内容。
我知道可以使用以下方式访问数据:
var data = CKEDITOR.instances.editable.getData();
但我不知道如何将数据发送到脚本,以便可以更新数据库。如果脚本每次有人取消选中
contenteditable
元素时运行,那就太棒了...但我不知道这是否可能。任何提示都会很好! :)
我的网站是使用php/mysql构建的。
我将使用CKeditor允许用户在登录后直接内联编辑页面内容。
我知道可以使用以下方式访问数据:
var data = CKEDITOR.instances.editable.getData();
contenteditable
元素时运行,那就太棒了...但我不知道这是否可能。像这样的东西:
CKEDITOR.disableAutoInline = true;
CKEDITOR.inline( 'editable', {
on: {
blur: function( event ) {
var data = event.editor.getData();
// Do sth with your data...
}
}
} );
请注意,此方法不适用于其他交互方式,例如:用户调用editor.setData()
或在编辑时关闭网页。这种情况下,内容将会丢失。如果我是你,我宁愿定期检查是否有新数据:
CKEDITOR.disableAutoInline = true;
var editor = CKEDITOR.inline( 'editable', {
on: {
instanceReady: function() {
periodicData();
}
}
} );
var periodicData = ( function(){
var data, oldData;
return function() {
if ( ( data = editor.getData() ) !== oldData ) {
oldData = data;
console.log( data );
// Do sth with your data...
}
setTimeout( periodicData, 1000 );
};
})();
CKEDITOR.inline('editable' ,{
on:{
blur: function(event){
if (event.editor.checkDirty())
console.log(event.editor.getData());
}
}
});
试一下这个。
看起来 "blur" 事件可能会对您有所帮助: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#event:blur
contenteditable="true"
添加到您的元素中,并设置CKEDITOR.disableAutoInline = false
。 - oleqCKEDITOR.inline( 'headline', { on: { blur: function( event ) {
- Dan TempleCKEDITOR.on( 'blur', function( event ) {} )
- oleqcontenteditable=true
的div上单击或失去焦点时,您最后一个命令定义的事件处理程序没有被调用... - Michael