在以下代码段中,一切都按预期工作,但是当我单击“显示源”时,Firefox 会产生此错误:
-- [11:07:30.630] TypeError: document.getElementbyId 不是函数@ http://localhost:8888/html5/native-rich-text.html:10
Safari 也会产生类似的错误。这是什么原因造成的?
function showSource() {
var content = document.getElementbyId("edit").innerHTML
content.replace(/</g, '<');
content.replace(/>/, '>: ');
prompt("Your Code:", content);
}
function createLink() {
var url = prompt("Enter URL:", "http://");
if (url)
document.execCommand("createlink", false, url);
}
<h1>Native Rich Text</h1>
<p>No textboxes here, that's a <div> element!</p>
<div>
<input type="button" value="Bold" onclick="document.execCommand('bold', false, null);">
<input type="button" value="Italic" onclick="document.execCommand('italic', false, null);">
<input type="button" value="Underline" onclick="document.execCommand('underline', false, null);">
<input type="button" value="Add Link" onclick="createLink();">
<input type="button" value="Show Source" onclick="showSource();">
</div>
<div id="edit" style="border:solid black; height: 300px; width: 400px;" contenteditable="true">
Hello!
</div>