国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

? cannot read properties of null(reading appendChild)解決辦法

這篇具有很好參考價(jià)值的文章主要介紹了? cannot read properties of null(reading appendChild)解決辦法。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

? 操作元素報(bào):cannot read properties of null(reading appendChild)解決辦法

1、場(chǎng)景:

寫的一個(gè)js渲染,但是出了個(gè)小問題,cannot read properties of null(reading appendChild)報(bào)錯(cuò)。

<div id="divps" class="divps"></div>

大致意思是:不能讀取空的屬性。

? cannot read properties of null(reading appendChild)解決辦法,Javascript基礎(chǔ),javascript,前端,html

2、解決方案

1、console.log() //打印數(shù)據(jù)內(nèi)容,查看獲取數(shù)據(jù)是否有問題。

2、js引入放body最后面,頁面是自上而下的運(yùn)行的,HTML都沒有運(yùn)行到,當(dāng)然獲取不到對(duì)應(yīng)節(jié)點(diǎn)

3、使用 getElementsByClassName(''div") 獲取元素時(shí),其返回的是數(shù)組,而沒有定位到某一具體對(duì)象

還有 getElementsByTagName() 方法也是,getElementsByTagName() 方法返回 HTMLCollection 對(duì)象,HTMLCollection 對(duì)象類似包含 HTML 元素的一個(gè)數(shù)組,看起來可能是一個(gè)數(shù)組,但其實(shí)不是,不過可以像數(shù)組一樣,使用索引來獲取元素

3、后期添加:

后期操作很多ES6里面的Array.form()也可以將這種類數(shù)組轉(zhuǎn)化為數(shù)組;

所以使用此類方法獲取元素時(shí),只需定位到某一具體元素,讓瀏覽器知道在哪個(gè)元素下添加子節(jié)點(diǎn)即可

改正如下:

document.getElementsByClassName(“divps”)[0];

或者直接拿ID文章來源地址http://www.zghlxwxcb.cn/news/detail-626557.html

document.getElementById(“divps”);

到了這里,關(guān)于? cannot read properties of null(reading appendChild)解決辦法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • npm ERR!Cannot read properties of null(reading ‘pickAlgorithm’)報(bào)錯(cuò)問題解決

    當(dāng)在使用npm包管理器或執(zhí)行npm命令時(shí),有時(shí)候會(huì)遇到“npm ERR!Cannot read properties of null(reading ‘pickAlgorithm’)”這個(gè)錯(cuò)誤提示,這是一個(gè)常見的npm錯(cuò)誤。 這個(gè)錯(cuò)誤提示通常說明在使用npm包管理器時(shí),執(zhí)行了某個(gè)npm命令,但是在執(zhí)行這個(gè)命令的過程中,出現(xiàn)了問題,可能是由于某

    2024年02月12日
    瀏覽(19)
  • 如何解決 npm ERR! Cannot read properties of null (reading ‘pickAlgorithm‘)報(bào)錯(cuò)問題

    如何解決 npm ERR! Cannot read properties of null (reading ‘pickAlgorithm‘)報(bào)錯(cuò)問題

    1、問題描述: ??????????? 在vue項(xiàng)目中,當(dāng)我們?cè)诮K端使用指令: npm install 下載 node_modules (節(jié)點(diǎn)_模塊) 時(shí)出現(xiàn)報(bào)錯(cuò)的情況。 node_modules是安裝node后用來 存放用包管理工具下載安裝的包的文件夾。 比如webpack、gulp、grunt這些工具。 主要是這個(gè)原因:npm ERR! Cannot read propert

    2023年04月18日
    瀏覽(33)
  • Vue報(bào)錯(cuò) Cannot read properties of undefined (reading ‘websiteDomains‘) 解決辦法

    Vue報(bào)錯(cuò) Cannot read properties of undefined (reading ‘websiteDomains‘) 解決辦法

    瀏覽器控制臺(tái)如下報(bào)錯(cuò): Unchecked runtime.lastError: The message port closed before a response was received. Uncaught (in promise) TypeError: Cannot read properties of undefined (reading \\\'websiteDomains\\\') ? ? at xl-content.js:1:100558 此問題困擾了很久,偶然看到一篇博文,說是迅雷擴(kuò)展問題 要想解決這個(gè)bug最有效的方

    2024年04月24日
    瀏覽(31)
  • “TypeError: Cannot read properties of null (reading ‘getContext‘)“

    “TypeError: Cannot read properties of null (reading ‘getContext‘)“

    目錄 一、報(bào)錯(cuò)截圖 二、使用場(chǎng)景 三、代碼截圖 四、報(bào)錯(cuò)原因 ?五、解決辦法 第一次在vue項(xiàng)目種使用canvas,跟著網(wǎng)上教程做,標(biāo)簽canvas寫好了,dom元素獲取了,簡(jiǎn)單“畫”了一下,運(yùn)行之后報(bào)\\\"TypeError: Cannot read properties of null (reading \\\'getContext\\\')\\\"的錯(cuò)。 意思是:找不到getContex

    2024年02月16日
    瀏覽(28)
  • [npm]Cannot read properties of null (reading 'pickAlgorithm')

    [npm]Cannot read properties of null (reading 'pickAlgorithm')

    在使用 npm install 命令安裝依賴時(shí),報(bào)出了 Cannot read properties of null (reading \\\'pickAlgorithm\\\') 這個(gè)錯(cuò)誤,這個(gè)可能是由于 npm 的緩存問題引起的。 解決方法如下,輸入命令: shell npm cache clear --force 清除一下 npm 的緩存,基本上應(yīng)該能行了。

    2024年02月09日
    瀏覽(32)
  • 錯(cuò)誤:ERROR Cannot read properties of null (reading ‘type‘)

    錯(cuò)誤:ERROR Cannot read properties of null (reading ‘type‘)

    ERROR Cannot read properties of null (reading ‘type’) TypeError: Cannot read properties of null (reading ‘type’) 改正后:?jiǎn)挝徽业皆?/p>

    2024年02月05日
    瀏覽(21)
  • Uncaught TypeError: Cannot read properties of null (reading ‘getAttribute‘)

    Uncaught TypeError: Cannot read properties of null (reading ‘getAttribute‘)

    簡(jiǎn)述:vue項(xiàng)目報(bào)錯(cuò), Uncaught TypeError: Cannot read properties of null (reading \\\'getAttribute\\\') , 翻譯:無法讀取null屬性(讀取\\\'getAttribute\\\'), 解析:getAttribute()是js獲取屬性方法,就是getAttribute不能讀取null的屬性, 這種錯(cuò)誤一般出現(xiàn)在使用Echarts和地圖后,當(dāng)切換到空白頁面后,重置頁面時(shí),

    2024年02月11日
    瀏覽(43)
  • Uncaught TypeError: Cannot read properties of null (reading ‘style‘)

    Uncaught TypeError: Cannot read properties of null (reading ‘style‘)

    Uncaught TypeError: Cannot read properties of null (reading \\\'style\\\') 2:報(bào)錯(cuò)的原因 文檔的加載過程是自上向下加載。使用未命名的變量、會(huì)報(bào)錯(cuò) 3;解決辦法 1、將Javascript代碼從標(biāo)簽中放入body中 2、 window.onload = function(){}框起來

    2024年02月15日
    瀏覽(51)
  • easyui Uncaught TypeError: Cannot read properties of null (reading ‘width‘)

    easyui Uncaught TypeError: Cannot read properties of null (reading ‘width‘)

    問題描述 在將easyui1.3.6版本替換為1.7版本的時(shí)候。只有表頭顯示出來了,內(nèi)容并沒有顯示出來,且報(bào)異常。表頭也沒有按照期望的寬度正常顯示。錯(cuò)誤提示如下 問題原因及解決辦法 該問題出現(xiàn)的原因是因?yàn)樵摫砀竦谋眍^涉及到跨行跨列問題,原因是最后一欄出貨記錄的跨列

    2024年02月16日
    瀏覽(26)
  • 配置hexo時(shí)TypeError: Cannot read properties of null (reading ‘xxx‘)

    配置hexo時(shí)TypeError: Cannot read properties of null (reading ‘xxx‘)

    這種報(bào)錯(cuò)的含義是在讀取文件時(shí)讀到了空對(duì)象。一般是文件放錯(cuò)了位置導(dǎo)致程序在指定的位置讀不到想要的文件導(dǎo)致的。 我是在更換hexo的theme時(shí)遇到的問題,我直接把github上的theme文件clone到了hexo的根目錄下了才有了這樣的報(bào)錯(cuò)。 只要把clone下來的theme文件保存到hexo根目錄下

    2024年02月11日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包