内嵌框架更改选择
iframe change selection
我正在创建一个非常简单的 rte,这是我的问题,我可以在 iframe(designmode=true) 中获取选定的文本,但我无法更改它。
.html
<a onclick="change();">change</a>
<iframe id="textEditor"></iframe>
脚本文件
function $(Str1){return document.getElementById(Str1);}
rte()
{
var texteditor=$('texteditor');
textEditor.document.designMode="on";
textEditor.document.body.contentEditable="True";
textEditor.document.open();
textEditor.document.close();
textEditor.focus();
}
function change()
{
var userSelection,range;
if (window.frames['textEditor'].getSelection)
{
userSelection=window.frames['textEditor'].getSelection();
}
else if(document.frames['textEditor'].selection)
{
userSelection=document.frames['textEditor'].selection.createRange();
}
if(userSelection.getRangeAt)
{
range=userSelection.getRangeAt(0);
}
else
{
range=document.frames['textEditor'].createRange();
range.setStart(userSelection.anchorNode,userSelection.anchorOffset);
range.setEnd(userSelection.focusNode,userSelection.focusOffset);
}
range="<div style='color:#f00;'>" + range + "</div>";
}
window.onload = rte();
可能是rte()
函数的第一行引用了"texteditor"而不是"textEditor"?
我找到了一种方法来解决这个问题,更改函数应该是这样的
function change()
if(document.selection)
{
sText=textEditor.document.selection.createRange();
sText.execCommand("createlink","","");
temp=sText.parentElement().innerHTML;
newNode=textEditor.document.createElement("h1");
replacement=sText.parentElement().replaceNode(newNode);
newNode.innerHTML=temp;
}
else if(document.getSelection)
{
sText=textEditor.window.getSelection();
myTag=textEditor.document.createElement("div");
myTag.setAttribute("class","bold");
sText.getRangeAt(0).surroundContents(myTag);
}
}
相关文章:
- 如何动态修改<选择>在实体化css框架中
- 内嵌框架更改选择
- Zend框架日期时间选择器
- 选择一个MVC框架(Javascript - 前端) - Backbone,Angular,Ember
- 播放框架:从下拉列表中选择值时更新网页
- 是否可以在GWT或任何其他JavaScript框架中选择垃圾收集算法
- 在离子框架中选择带有离子滚动的中间项目
- 在组合框选择时动态创建框架(和按钮单击)
- 框架选择器问题
- 选择框架内的所有 html 选择元素
- jQuery 单击事件选择选项不适用于 jQuery Mobile 框架
- 如何在JavaScript依赖框架之间进行选择
- 对于一个html5平板电脑网站的助手和框架来说,什么是伟大的现代选择'的前端
- PHP或Javascript,通过元素ID点击或选择框架中的元素
- 在InDesign CS6中选择组内部的text框架
- 我对javascript框架和javascript UI库的选择
- 选择一个JS框架(从Mootools切换到Closure或Dojo)
- 重复->选择播放框架中的标签
- FB好友选择器框架在https中,不能与http中的托管页面交互
- 论文.js框架"选择大纲"