Javascript 如何制作一个按钮,将所选文本包装到具有特定类的div中?

Javascript 如何制作一个按钮,将所选文本包装到具有特定类的div中?,javascript,jquery,nicedit,Javascript,Jquery,Nicedit,我正在我的网站的管理面板的文本区域中使用nicedit。现在,我想添加一个自定义按钮,使所选文本在class=info的div中换行。 我使用了nicedit wiki中的信息。这是我到目前为止的js文件代码: /** * nicInfodiv * @description: Adds blue square wrapper to text * @requires: nicCore, nicPane, nicAdvancedButton * @author: Brian Kirchoff * @

我正在我的网站的管理面板的文本区域中使用nicedit。现在,我想添加一个自定义按钮,使所选文本在class=info的div中换行。 我使用了nicedit wiki中的信息。这是我到目前为止的js文件代码:

/**
* nicInfodiv
* @description: Adds blue square wrapper to text
* @requires: nicCore, nicPane, nicAdvancedButton
* @author: Brian Kirchoff
* @version: 0.9.0
*/

/* START CONFIG */
var nicInfodivOptions = {
    buttons : {
        'infodiv' : {name : __('Some alt text for the button'), type : 'nicEditorInfodiv'}
    }/* NICEDIT_REMOVE_START */,iconFiles : {'infodiv' : '/js/nicInfodiv/icons/div.gif'}/* NICEDIT_REMOVE_END */
};
/* END CONFIG */

var nicEditorInfodiv = nicEditorButton.extend({   
  mouseClick : function() {
   //WHAT SHOULD I WRITE HERE????
  }
});

nicEditors.registerPlugin(nicPlugin,nicInfodivOptions);
我到处都找不到帮助。有人能给我在mouseclick事件中编写的适当代码,以便它将div class=info包装添加到所选文本中吗? 谁能帮帮我吗

您可以使用


谢谢,但我需要将包装器div添加到所选文本中,而不是我单击的按钮中。哇,对不起。您可以使用
window.getSelection().toString()
访问DOM的选定文本。然后,使用jQuery选择器访问该文本,并使用它而不是
this
$(this).wrap('<div class="info"></div>');
$(this).parent().addClass('info');