Javascript 如何用按钮替换编辑区中的文本,该按钮具有单击添加到url文本的功能

Javascript 如何用按钮替换编辑区中的文本,该按钮具有单击添加到url文本的功能,javascript,jquery,Javascript,Jquery,我在moodle的tinymce编辑器中的一个栏上创建了一个插件按钮 我需要使这个插件按钮做到这一点:替换编辑区中选定的文本与一个按钮,按钮的名称应作为被替换的文本。然后我需要这个按钮有一个功能来播放音频与该链接:,其中文本=替换文本 一般来说,点击tinymce插件按钮可以将文字转换成语音按钮,该按钮使用谷歌服务为文字发声 我缺少的部分是插件代码。这里是我迄今为止发现的,请参见示例: 欢迎来到SO。不清楚你需要什么。请将您的问题简化为具体问题。为什么您要在问题中添加jquery标记,但在代码中

我在moodle的tinymce编辑器中的一个栏上创建了一个插件按钮 我需要使这个插件按钮做到这一点:替换编辑区中选定的文本与一个按钮,按钮的名称应作为被替换的文本。然后我需要这个按钮有一个功能来播放音频与该链接:,其中文本=替换文本

一般来说,点击tinymce插件按钮可以将文字转换成语音按钮,该按钮使用谷歌服务为文字发声

我缺少的部分是插件代码。这里是我迄今为止发现的,请参见示例:


欢迎来到SO。不清楚你需要什么。请将您的问题简化为具体问题。为什么您要在问题中添加jquery标记,但在代码中不使用jquery库?2如果dont2Isherwood,则可能需要删除,具体问题是我不知道如何使任务的第二部分和第三部分正常工作。现在它用一个按钮替换一个文本,但按钮需要用它替换的文本命名。这个新按钮的onclick功能应该会将该文本添加到我发布的链接中,这样最终的产品将是一个用户可以单击的按钮,它会将替换的文本发音。
function replaceSelection(html) {
var sel, range, node;

if (typeof window.getSelection != "undefined") {
    // IE 9 and other non-IE browsers
    sel = window.getSelection();

    // Test that the Selection object contains at least one Range
    if (sel.getRangeAt && sel.rangeCount) {
        // Get the first Range (only Firefox supports more than one)
        range = window.getSelection().getRangeAt(0);
        range.deleteContents();

        // Create a DocumentFragment to insert and populate it with HTML
        // Need to test for the existence of range.createContextualFragment
        // because it's non-standard and IE 9 does not support it
        if (range.createContextualFragment) {
            node = range.createContextualFragment(html);
        } else {
            // In IE 9 we need to use innerHTML of a temporary element
            var div = document.createElement("div"), child;
            div.innerHTML = html;
            node = document.createDocumentFragment();
            while ( (child = div.firstChild) ) {
                node.appendChild(child);
            }
        }
        range.insertNode(node);
    }
} else if (document.selection && document.selection.type != "Control") {
    // IE 8 and below
    range = document.selection.createRange();
    range.pasteHTML(html);
}
}