我决定在项目中使用NicEdit,因为它是轻量级的。
因此,现在我在我的页面中有一个可变数量的实例,在单击时加载,在编辑器模糊时删除。
我需要知道如何从这个组件中解除绑定事件。我试着手动解绑它,但是我不知道它们链接在哪里!
$('.container').bind('click', function(){
var _form = $(this).parentsUntil('form').parent();
var textarea = _form.find('textarea.edit');
var ta_id = textarea.attr('id');
var ed = new nicEditor(niceditOptions).panelInstance(ta_id);
// Show Preview and update textarea and so on
ed.addEvent('blur', function() {
var _ed = nicEditors.findEditor(ta_id);
var ev_type, evt, events = this.eventList;
for (ev_type in events){
for (evt in ev_type){
if (this.removeEventListener){
this.removeEventListener(ev_type, events[ev_type][evt]);
}
else {
this.detachEvent('on' + ev_type, events[ev_type][evt]);
}
}
}
this.removeInstance(ta_id);
});
});非常感谢!大卫。
发布于 2012-10-19 15:48:00
你的解决方案可能还有其他方法,但在这种情况下,我更喜欢使用one版本的nicEditor面板并绑定我所有的所见即所得实例。这样做的原因是我认为它稍微整洁了一些。我将假设您知道如何使用bind one editor to multiple editable instances。
加载时,我的HTML可能如下所示:
<div id="instance1">text</div>
...
<div id="instance2">text</div>
...
<div id="myNicPanel" style="display:none;position:relative;"></div>因此,一旦页面完成加载周期,我应该有两个可编辑的区域和一个隐藏的编辑器。然后,当选择要编辑的实例时,我将使用以下jQuery重新定位并显示编辑器:
$('#instance1 , #instance2').click(function () {
//Reposition the editor to just above the selected instance
$('#myNicPanel').css({
top: $(this).position().top,
left: $(this).position().left,
display: 'block',
width: $(this).width() - 2 //manual adjustment,
position: 'absolute'
});
//Make the width of the editor equal to that of the instance
$('#myNicPanel').css({
top: $(this).position().top - $('#myNicPanel').height()
});
});当然,在此之前,您已经启动了编辑器和实例,如果您还想让编辑器在模糊时再次隐藏,您可以将hide()函数附加到其中一个nicEditor events。
https://stackoverflow.com/questions/12779717
复制相似问题