一直返回false,请问要怎么使用?求指点
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
#editor {
border: 1px solid red;
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<input value="设置瞄点" id="edit-btn" type="button">
<iframe id="editor"></iframe>
<script>
let editor = document.getElementById("editor").contentWindow
editor.document.designMode = "on";
editor.document.body.innerHTML = '<div>内容可以编辑</div>'
var btn = document.getElementById('edit-btn');
btn.onclick = function () {
editor.document.execCommand("CreateBookmark", false, 'name');
alert(editor.document.execCommand("CreateBookmark", false, 'name'))
}
</script>
</body>
</html>
"CreateBookmark"命令不存在吧?
document.execCommand - Web API 接口参考 | MDN 当一个HTML文档切换到设计模式时,document暴露 execCommand 方法,该方法允许运行命令来操纵可编辑内容区域的元素。 https://developer.mozilla.org/zh-CN/docs/Web/API/Document/execCommand#%E5%91%BD%E4%BB%A4