开发者

selectionStart for non textarea elements

$(element)[0].selectionStart seems to only work for textareas. Is there an alternative for non textareas

I'm trying to wrap strings withi开发者_如何学运维n DOM elements in tags (bold, italic...)

Also, how do I undo the wrapping?


This is a tricky area. You need the Selection object and DOM Range. However, IE does this all completely differently to proper browsers.

Wrapping the selection inside tags is also non-trivial in general: you need to consider all the text nodes within the selection.

My Rangy library normalizes the Selection/Range API for IE and has a module to apply a CSS class to a selection, which may help you to some degree. I'm also planning to write a more general module for applying other styles to a selection/range.

Sorry for the shameless self-promotion, but short of writing a lot of code yourself I don't know what else to suggest.


use the jQuery fieldSelection plugin http://plugins.jquery.com/project/fieldselection

i use it in my script that strips tags on paste and it seems to work great. http://blog.brokenbytes.info/2010/09/stripping-tags-on-paste-using-jquery/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜