0

我正在使用富文本编辑器,并且正在尝试向其中添加代码标记功能。编辑器现在有 2 个按钮。一个是下划线,另一个是代码

当我选择文本并单击下划线按钮时,所选文本将带下划线,但是当我选择文本并单击代码按钮时,它不起作用。

我已经添加了代码标签选项,但它不起作用

代码:

document.writeln('<td><img class="rteImage" src="' + imagesPath + 'underline.gif" width="25" height="24" alt="Underline" title="Underline" onClick="rteCommand(\'' + rte + '\', \'underline\', \'\')"></td>');
document.writeln('<td><img class="rteImage" src="' + imagesPath + 'code.gif" width="25" height="24" alt="Code" title="Code" onClick="rteCommand(\'' + rte + '\', \'code\', \'\')"></td>');

在上面的代码中,我使用了 Underling 和代码标签作为下划线和代码按钮,它们都使用相同的 javascript 函数。下划线工作正常,但是当我选择代码部分并单击代码按钮时,它不起作用

Javascript函数代码:

function rteCommand(rte, command, option) {
    //function to perform command
    var oRTE;
    if (document.all) {
        oRTE = frames[rte];
    } else {
        oRTE = document.getElementById(rte).contentWindow;
    }
    alert(command);

    try {
        oRTE.focus();
        oRTE.document.execCommand(command, false, option);
        oRTE.focus();
    } catch (e) {
    }
}

我该如何解决这个问题?

4

1 回答 1

1

由于第一个正在工作,我认为您应该创建一个单独的函数来处理“代码”按钮

于 2013-11-14T11:57:45.713 回答