2013-01-05 4 views
15

ではありませんがすべてが期待どおりに動作しますスニペットが、私がクリックしたときに「ソースコードを表示」Firefoxは、このエラー生成:例外TypeError:のdocument.getElementByIdは、以下では機能

 
-- 
[11:07:30.630] TypeError: document.getElementbyId is not a function @ http://localhost:8888/html5/native-rich-text.html:10 

をとSafariは、同様のエラーを生成します。これを引き起こしているのは何ですか?

function showSource() { 
 
    var content = document.getElementbyId("edit").innerHTML 
 
    content.replace(/</g, '&lt;'); 
 
    content.replace(/>/, '&gt: '); 
 
    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 &lt;div&gt; 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>

答えて

31

ケース:document.getElementById(資本Bに注意してください)。

+2

ローカライズされすぎても、この質問が私を助けていることが判明しました。この答えをありがとう! –

+0

それは私を助けた!ありがとう! –

+0

5年後、それは私が大文字にしなかった正確なものです。ありがとうございました。 – Guy

10

JavaScriptの大文字と小文字が区別されます。 bgetElementbyIdは大文字にする必要があります。敏感

var content = document.getElementById("edit").innerHTML; 
関連する問題