【问题标题】:jQuery appending & prepending some texts to selected words on textareajQuery 在 textarea 上的选定单词上附加和附加一些文本
【发布时间】:2011-10-21 17:54:19
【问题描述】:

我有一个文本区域和这个文本区域上方的一个按钮。我想在这个文本区域中选择一个单词,然后在选定的单词前面加上一些符号。

例如:

hello -> (hello) // 我想在单击 textarea 上方或下方的一个按钮时添加“(”并添加“)”。但我不知道如何用选定的单词来做?

【问题讨论】:

    标签: jquery select focus textarea


    【解决方案1】:

    我强烈建议您使用:jQuery - fieldSelection

    函数有:getSelection()replaceSelection(text)

    所以你可以这样做:

    var before = $(this).getSelection();
    $(this).replaceSelection(prepend + before + append);
    

    【讨论】:

      猜你喜欢
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 2021-06-01
      • 2011-06-11
      • 1970-01-01
      • 2016-08-04
      • 2012-01-03
      相关资源
      最近更新 更多