读书人

请问一个createRange().pasteHTML的有

发布时间: 2012-04-06 12:22:24 作者: rapoo

请教一个createRange().pasteHTML的问题
页面上有个IFRAME,<iframe style="width: 100%; height: 200px;" id="editor"></iframe>,要求光标处插入一段HTML代码

function paste(content) {
document.frames["editor"].document.selection.createRange().pasteHTML(content)
}
$("#test").click(function () {
paste('<b>插入点</b>');
});
以上可以插入代码,但存在2个问题:1、必须在IFRAME中选择一段文字才能进行pasteHTML 2、粘贴进去的HTML标签都转换成大写的了比如<B>插入点</B>
请教如何能在当前光标处插入代码,并且代码标签转换为小写


[解决办法]

JScript code
function paste(content) {  if(document.frames["editor"].document.selection.createRange().text!='')    document.frames["editor"].document.selection.createRange().pasteHTML(content)  } 

读书人网 >JavaScript

热点推荐