Man*_*noz 4 javascript jquery rich-text-editor razor asp.net-mvc-4
我正在研究富文本编辑器,直到现在都做得很好.我已经创建了一个单独的.js文件来将其用作插件.
现在我想通过文件给它一个类名来使用这个插件.但.cshtml它似乎不起作用,我已经搜索了相关的答案,他们说使用document.getElementsByClassName将解决我的问题.
请仔细阅读此代码并告诉我出了什么问题?
文本编辑器.js -
var richTextEditor = document.getElementsByClassName("text-editor");
richTextEditor.contentDocument.designMode = 'ON';
$('#strong').live('click', function () {
richTextEditor.contentDocument.designMode = 'ON';
richTextEditor.contentDocument.body.contentEditable = true;
richTextEditor.contentDocument.execCommand('bold', false, null);
richTextEditor.focus();
});
Run Code Online (Sandbox Code Playgroud)
cshtml文件 -
<script src="/js/Texteditor.js" type="text/javascript"></script>
<script src="/js/jquery.js" type="text/javascript"></script>
<div id="strong" class="command btn"><i class="icon-bold icon-black"></i></div>
<iframe id="edtNoteCreate" class="text-editor" name="DisplayNote" style="width:430px;height:150px;">@((Model.Note != null ? Model.Note : ""))</iframe>
Run Code Online (Sandbox Code Playgroud)
只需获取匹配节点的第一项; 它是一个NodeList,但可以像数组一样解除引用.
var richTextEditor = document.getElementsByClassName("text-editor")[0];
Run Code Online (Sandbox Code Playgroud)