TypeError:document.getElementbyId不是函数 [英] TypeError: document.getElementbyId is not a function

查看:2005
本文介绍了TypeError:document.getElementbyId不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码段中,一切都按预期工作,但是当我点击显示源代码时,Firefox会产生此错误:

In the following snippet everything works as expected, but when I click "Show Source" Firefox produces this error:


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

Safari也会产生类似的错误。造成这种情况的原因是什么?

And Safari produces a similar error. What is causing this?

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>

推荐答案

区分大小写: document.getElementById (注意大写 B )。

Case sensitive: document.getElementById (notice the capital B).

这篇关于TypeError:document.getElementbyId不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆