var insertHTML = function(node , html ,where) {
if(node.ownerDocument.createRange) {
var range = node.ownerDocument.createRange();
switch(where) {
case "beforebegin" :
range.setStartBefore(node);
var n = range.createContextualFragment(html);
node.parentNode.insertBefore(n , node);
break;
case "afterbegin" :
range.setStartAfter(node);
if(node.firstChild) {
var n = range.createContextualFragment(html);
node.insertBefore(n , node.firstChild);
} else {
node.innerHTML = html;
}
break;
case "beforeend":
range.setEndBefore(node);
if(node.lastChild) {
var n = range.createContextualFragment(html);
node.appendChild(n);
} else {
node.innerHTML = html;
}
break;
case "afterend" :
range.setEndAfter(node);
var n = range.createContextualFragment(html);
if(node.nextSibling) {
node.parentNode.insertBefore(n , node.nextSibling);
} else {
node.parentNode.appendChild(n);
}
}
} else {
switch(where) {
case "beforebegin" :
node.insertAdjacentHTML("BeforeBegin" , html);
break;
case "afterbegin" :
node.insertAdjacentHTML("AfterBegin" , html);
break;
case "beforeend" :
node.insertAdjacentHTML("BeforeEnd" , html);
break;
case "afterend" :
node.insertAdjacentHTML("AfterEnd" , html);
}
}
};
分享到:
相关推荐
**UEditor富文本编辑器**是一款广泛应用于Web开发中的强大编辑工具,由百度公司开发,提供了丰富的API和自定义功能,使得开发者可以轻松地在网页上实现文本编辑、格式化、图片上传等功能。本资源包主要包含UEditor的...
- 将`FCK.InsertHtml(inImg); var newCode = FCK.CreateElement('DIV'); newCode.innerHTML = inImg;` 改为 `FCK.InsertHtml(inImg);` - 同样地,将`FCK.InsertHtml(iimghtml); var newCode = FCK.CreateElement('...
例如,下面的 JavaScript 函数 `InsertHTML` 可以插入指定的代码: ```javascript function InsertHTML(value) { tinyMCE.execCommand('mceInsertContent', false, value); } ``` 在这个例子中,`value` 参数是你...
插入HTML内容到编辑器中使用`InsertHtml`方法: ```javascript oEditor.InsertHtml("html"); ``` 这里的`html`参数是你要插入的HTML文本。 ### 5. 检查内容是否改变 `IsDirty`方法可以用来检查编辑器内容是否被...
在UEditor中,使用`UEditor.all('editor_id').execCommand('insertHtml', html)`方法可以将HTML内容插入到编辑器中。 接着,我们关注后端部分,这里是使用ASP.NET实现文件上传和转换的关键。在ASP.NET中,我们可以...
[#2412] FCK.InsertHtml() is now properly removing selected contents after content insertion in Firefox. [#2420] Spelling mistake corrections made by the spell checking dialog are now undoable. [#...
[#2412] FCK.InsertHtml() is now properly removing selected contents after content insertion in Firefox. [#2420] Spelling mistake corrections made by the spell checking dialog are now undoable. [#...
在这个例子中,`window.clipboardData.getData('text/plain')`获取的是纯文本数据,然后通过`insertHtml`方法将这个纯文本插入到编辑器中,从而实现了文本化的粘贴。 此外,还可以考虑使用HTML解析库,如`DOMParser...
- **插入内容**:可以使用`InsertHtml`方法向编辑器中插入HTML内容。 ```javascript oEditor.InsertHtml("html"); ``` - **检查内容是否变化**:使用`IsDirty`方法判断编辑器内容是否已被修改。 ```javascript ...
- 插入HTML片段:使用`InsertHtml`方法,传入要插入的HTML文本。 ```javascript oEditor.InsertHtml("html"); ``` 4. **检查内容是否改变** - 使用`IsDirty`方法可以检测FCKeditor的内容是否发生了变化。 ...
oEditor.InsertHtml('<img src="image.jpg" />'); // 检查编辑器内容是否被修改 var isModified = oEditor.IsDirty(); // 执行FitWindow命令 oEditor.Commands.GetCommand('FitWindow').Execute(); ``` #### 七、...
Ext.get('id').insertHtml({ where: 'beforeBegin', // beforeBegin, afterBegin, beforeEnd, afterEnd el: 'referenceElement', html: '<p>Example HTML</p>' }); ``` #### 五、其他实用技巧 - **创建子...
KindEditor是一套开源的HTML可视化编辑器,主要用于让用户在网站上获得所见即所得编辑效果,兼容IE、Firefox...7)新接口:引入KE.html, KE.text, KE.selectedHtml, KE.insertHtml, KE.appendHtml, KE.isEmpty等函数。
例如,可以使用`QTextEdit::insertPlainText()`或`QTextEdit::insertHtml()`来插入文本,`QTextEdit::textCursor()`获取当前的文本光标,然后通过`QTextCursor`类进行更精确的文本操作。 3. **事件处理**:QT中的...
editor.insertHtml('这是插入的文本</p>'); ``` 6. **插件开发** KindEditor支持插件扩展,开发者可以通过编写JavaScript代码实现自定义功能。插件通常包含注册、初始化、销毁等生命周期方法。例如,创建一个...
editor.InsertHtml('这是一段新的文本。</p>'); } // 设置编辑器的 OnComplete 事件 FCKeditorAPI.OnComplete = onEditorComplete; // 获取编辑器实例 var oEditor = FCKeditorAPI.GetInstance('InstanceName'); ...
oEditor.InsertHtml("这是一段加粗的文本</strong>"); ``` 8. **检查FCK编辑器内容是否发生变化**: ```javascript oEditor.IsDirty(); ``` - **功能说明**: 该方法用于检查编辑器内容是否与初始状态有所变化...
5. **实现编辑功能**:使用`insertHTML`方法将特定的HTML代码插入到选中的位置,以实现如加粗、斜体等功能。 #### 结论 HTML在线编辑器极大地提升了用户在网络环境中创建和编辑富文本内容的能力,同时降低了技术...
- 方法调用:使用编辑器提供的方法,如`insertHTML`插入HTML代码,`getText`获取纯文本,`focus`使编辑器获取焦点等。 5. **uniapp富文本编辑器的优化点**: - 性能优化:可能包含了延迟加载、内存管理等策略,...
- `InsertHtml`:插入HTML文本到编辑器中。 - `IsDirty`:检查编辑器内容是否被修改过。 4. **执行命令** - FCKeditor提供了许多内置命令,如`DocProps`, `Templates`, `Link`, `Image`等。要执行命令,首先通过...