开发者

how to add a simple button that will inject a tag into a textarea?

I want to create a simple button t开发者_Python百科hat will inject a [b][/b] into a textarea.

How can I do this?


Your question is tagged jQuery, so I assume you're using it:

HTML:

<button id="mybutton>Bold</button>
<textarea id="mytextarea"></textarea>

JS:

$('mybutton').click(function(){
    $('#mytextarea').append('[b][/b]');
});

Of course, a real BBCode implementation with the ability to surround highlighted text with [b] tags, and/or append [b] upon the first click of the button and [/b] upon the second, is another problem entirely.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜