gpt4 book ai didi

javascript - 无法在 Internet Explorer 中打开 designMode

转载 作者:行者123 更新时间:2023-11-30 10:54:39 24 4
gpt4 key购买 nike

以下代码在 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 中,警报显示为“关闭”,然后是“打开”;在 IE 中,它们都处于“关闭”状态。

我做错了什么?

最佳答案

即使这不会改变警报显示的内容,它也会在 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 的解决方法。

关于javascript - 无法在 Internet Explorer 中打开 designMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2850609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com