将标签插入文本区域
我正在开发自己的论坛软件,现在正在做编辑器。 好吧,我想制作一些 ofc 标签,例如 [b] 和 [i]。
我怎样才能做到这一点?好吧,我找到了这个线程: Insert text into textarea with jQuery
并使用了这个:
$('a').click(function() //this will apply to all anchor tags
{
$('#area').val($('#area').val()+'[b][/b]');
})
但我也想在标签之间、[b] 和 [/b] 之间指向正确的位置,我该怎么做?
I'm developing my own forum software, and i am now doing the editor.
Well i want to make some tags ofc, like [b] and [i].
How can i do that? Well, i found this thread: Insert text into textarea with jQuery
and used this:
$('a').click(function() //this will apply to all anchor tags
{
$('#area').val($('#area').val()+'[b][/b]');
})
But i also want to point just right between the tags, between the [b] and the [/b], how can i do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅此问题: jQuery Set Cursor Position in Text Area
/edit:抱歉,这已经在评论中得到了回答。
See this question: jQuery Set Cursor Position in Text Area
/edit: Sorry this was already answered in the comments.
如果这超出了范围,请直接说出来,但您也可以使用 JQuery selectedText 插件。我认为这可能对您的最终产品有帮助(否则,对于您的问题,比利·穆恩提到的上一个问题就足够了)
If this is out of scope, please just say it, but you can also select text and wrap them in the [b][/b] tags by using the JQuery selectedText plugin. I think it might be helpful for your final product (otherwise, for your question, the previous question as mentioned by Billy Moon is sufficient)