execCommand的问题

wang2438545 2008-07-19 09:56:19
我在IE中用document.execCommand('InsertTextArea',true,"a");
在页面上插入一个'TextArea',id是‘a’,可是怎么给这个TextArea指定name?
还有,在firefox中怎么实现同样的功能?
...全文
63 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueDestiny 2008-07-20
  • 打赏
  • 举报
回复
兼容版~IE,FF,opera,safari:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Rank's HTML document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="ImageToolbar" content="no" />
<meta http-equiv="Creator.name" content="Rank, BlueDestiny, never-online" />
<style type="text/css" title="default" media="screen">
/*<![CDATA[*/

/*]]>*/
</style>

</head>
<body>
<script type="text/javascript">//<![CDATA[
onload = function () {
function insertBox(id) { return '<input id="' +id+ '" value="never-online.net/blog">'; }
var sHTML = insertBox('myid') +'<a href="http://www.never-online.net">never-online</a>';
var iframe=document.getElementById('frm').contentWindow;
iframe.document.designMode="on";
iframe.document.writeln('<body id="never-online.net"></body>');
if(!!window.ActiveXObject) {
iframe.document.body.focus();
var doc=iframe.document;
var range= doc.selection.createRange();
if(doc.selection.type=="Control") {
var range2=doc.body.createTextRange();
range2.moveToElementText(range.item(0));
range2.select();
range=range2;
}
range.pasteHTML(sHTML);
} else {
iframe.document.execCommand('insertHTML',false,sHTML);
}
alert(iframe.document.body.innerHTML)
}

//]]></script>
<iframe src="about:blank" id="frm"></iframe>
</body>
</html>

87,918

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧