WYSIWYG again, IE simplest execCommand

99封情书 提交于 2019-12-11 15:55:37

问题


I wrote the simplest WYSIWYG in js/jquery: http://jsfiddle.net/XnSWF/

Works perfectly (eg. set to write in bold or set bold on selected text) on newset Opera 11, Chrome 16, Firefox 9 and Safari 5.1 but in IE9 I can't set bold to selected text and always when i use bold button, this carret go to first line to first letter...

Why?


回答1:


It's because the selection is destroyed before the click event fires in IE. You can get round this by using the the mousedown event instead, or (better) by making the button text unselectable:

$('<li class="wysiwyg-bold"><b unselectable="on">textBold</b></li>')
    .appendTo('.wysiwyg-toolbar');

Live demo: http://jsfiddle.net/XnSWF/1/



来源:https://stackoverflow.com/questions/9053263/wysiwyg-again-ie-simplest-execcommand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!