当然,程序是没有错误。但是,ie没有办法知道你想把哪些文字做成链接呀。你在你的编辑区选择一些文字,再执行你的这段代码,就可以看到效果了。
如果你想程序自动选择文字,而无须用户干预,可以先 execCommand("selectAll")
再创建链接
<iframe></iframe>
<script>
window.onload=function(){document.frames[0].window.document.designMode="On"}
var doc=document.frames[0].window.document;
var add=function(){doc.focus();doc.execCommand("CreateLink",false,"http://www.163.net");}
</script><button onclick="add()">手动选择文字后插入链接</button>
<button onclick="doc.focus();doc.execCommand('selectAll');add()">自动选择并插入链接</button>
<button onclick="alert(doc.body.innerHTML)">查看</button>