解决JS 中 innerHTML is not a function

document.getElementById(…).innerHTML is not a function

在用js往HTML页面动态添加内容时,如 写成

document.getElementById(...).innerHTML("

Hello World

")

会报出找不到这个函数的错误 (is not a function)
解决方法:

  1. 把函数的字符串参数用变量存储之后,把变量传进去
  2. document.getElementById(...).innerHTML = "

    Hello World

    "

    innerHTML后面是 = 不是函数调用!!

你可能感兴趣的:(解决办法,web)