以下代码可以在Firefox 3.6中运行,但不能在Internet Explorer 8中运行:
<html>
<head>
<title>Example</title>
<script type="text/javascript">
function init() {
alert(document.designMode);
document.designMode = "on";
alert(document.designMode);
}
</script>
</head>
<body onload="init()">
</body>
</html>在FF中,警报显示为“Off”,然后显示为“on”;在IE中,它们都是“Off”。
我做错了什么?
发布于 2010-05-18 00:06:52
即使这不会改变警报显示的内容,它也会在IE中打开可编辑模式:
<html>
<head>
<title>Example</title>
<script type="text/javascript">
function init() {
alert(document.designMode);
document.designMode = "On";
document.body.contentEditable = 'true';
alert(document.designMode);
}
</script>
</head>
<body onload="init()">
</body>
</html>您可以通过在页面主体中放置一些虚拟内容(如<p>Test</p>)并在FF和IE中加载来进行测试。至少对于IE8来说,这是一种合适的变通方法。
发布于 2010-05-18 00:01:26
尽管designMode是IE的标准,但你在IE中使用contentEditable属性可能会更好一些。
发布于 2010-05-17 23:59:35
Internet Explorer documentation似乎指示designMode属性区分大小写,并且需要设置为"On",而不是"on"。
https://stackoverflow.com/questions/2850609
复制相似问题