开发者

How to apply some actions to selected text of a div in jquery?

I need to apply some styles to selected text inside a div, like we can do in MS Word. I could not find any way to get the selected开发者_运维知识库 text :(

Thanks


Take a look at this:

http://api.jquery.com/select/


If you just need to style it while it's selected, there's the CSS3 ::selection pseudo-class. This doesn't work in jQuery though.


Get the jQuery plugin from: http://github.com/localhost/jquery-fieldselection

Then in Your script tag play with it:

$('input[@type="text"], textarea, p').keyup(update).mousedown(update).mousemove(update).mouseup(update);

function update() {
   var range = $(this).getSelection();
   $('#output').html(range.start + range.end + range.length);
}



This links might be helpfoul:

snipplr.com/view/775/getselection/ - Support: IE6, Fx2, Opera9, Safari Cross browser getSelection().

stackoverflow.com/questions/717224/how-to-get-selected-text-in-textarea/717226#717226 - How to get selected text in textarea?

stackoverflow.com/questions/2236982/jquery-select-text-and-add-span-to-it-in-an-paragraph

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜