开发者

Boldening text "Inside" a textarea

I have a textarea #myarea into which I'm typing text. I've typed this text.

This is a sentence and only this word will end up being bolded

Now I have a butt开发者_JAVA百科on on the side, like a bold button. I want to select the letters I want bolded, click the button, and see those letters turn bold inside the textarea. It's similar to the standard functionality found in many editors, but I'm looking for something much simpler as I described here.

So is there a way to do this with jquery? I'm guessing it's a 2-part problem. I need to find the letters selected, then apply bold to them so it shows bold inside the textarea.


If you don't mind using a div that has its ContentEditable property set to true then you can easily do this using:

document.execCommand('bold',null,false);

You can easily style this div to look and feel like a textarea.

See jsFiddle here: http://jsfiddle.net/hqvDT/1/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜