Last active
March 28, 2016 02:37
-
-
Save zy108830/79d990ad5e2a326fcd41 to your computer and use it in GitHub Desktop.
利用wangEditor快速初始化一个文本编辑器;明白事件的重复绑定机制
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*初始化一个富文本编辑器*/ | |
<a id="trigger-modal" class="btn btn-primary hidden" data-toggle="modal" href="#modal-editor">Trigger modal</a> | |
<div class="modal fade" id="modal-editor"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | |
<h4 class="modal-title">内容编辑</h4> | |
</div> | |
<div class="modal-body"> | |
<div id="editor" style="height: 300px;"></div> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default action-cancel" data-dismiss="modal">取消</button> | |
<button type="button" class="btn btn-primary action-ok">确定</button> | |
</div> | |
</div><!-- /.modal-content --> | |
</div><!-- /.modal-dialog --> | |
</div><!-- /.modal --> | |
var wenjuan_remark=new wangEditor('editor'); | |
wenjuan_remark.config.menus=[ | |
//'source', | |
//'|', | |
'bold', | |
'underline', | |
'italic', | |
'strikethrough', | |
'eraser', | |
'forecolor', | |
'bgcolor', | |
'quote', | |
'fontfamily', | |
'fontsize', | |
'head', | |
'unorderlist', | |
'orderlist', | |
'alignleft', | |
'aligncenter', | |
'alignright', | |
'link', | |
'unlink', | |
'table', | |
//'emotion', | |
'img', | |
//'video', | |
//'location', | |
//'insertcode', | |
//'|', | |
'undo', | |
'redo', | |
'fullscreen' | |
]; | |
/*问卷说明*/ | |
wenjuan_remark.config.customUpload = true; // 设置自定义上传的开关 | |
wenjuan_remark.config.customUploadInit = uploadInit; // 配置自定义上传初始化事件,uploadInit方法在上面定义了 | |
wenjuan_remark.create(); | |
$('#wenjuan_remark').click(function(){ | |
var $this=$(this); | |
wenjuan_remark.$txt.html($this.html()); | |
/*如果在事件绑定函数中还有事件绑定函数,就会造成重复绑定*/ | |
$('#trigger-modal').trigger('click'); | |
$('#modal-editor').find('.action-calcel').unbind('click'); | |
$('#modal-editor').find('.action-calcel').click(function(){ | |
$('#modal-editor').find('.close').trigger('click'); | |
}); | |
$('#modal-editor').find('.action-ok').unbind('click'); | |
$('#modal-editor').find('.action-ok').click(function(){ | |
console.log($this.length); | |
$this.html(wenjuan_remark.$txt.html()); | |
$('#modal-editor').find('.close').trigger('click'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment