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.
精彩评论