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

JS常見報錯解決辦法:Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)

這篇具有很好參考價值的文章主要介紹了JS常見報錯解決辦法:Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML’)意思是,
未捕獲類型錯誤:無法設(shè)置空屬性(設(shè)置“innerHTML”),
也就是說**.innerHTM**前的對象內(nèi)容是空或null。

1、舉個例子,我需要用js渲染HTML網(wǎng)頁的數(shù)據(jù)。
JS常見報錯解決辦法:Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘),前端,javascript,前端,html
報錯:
Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML’)
自然是未實現(xiàn)想要的渲染效果。
JS常見報錯解決辦法:Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘),前端,javascript,前端,html
2、當(dāng)我將要插入的js文件放在body的后面,錯誤就解決了
JS常見報錯解決辦法:Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘),前端,javascript,前端,html
實現(xiàn)了想要的數(shù)據(jù)渲染效果。
JS常見報錯解決辦法:Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘),前端,javascript,前端,html

3、瀏覽器工作原理
由于瀏覽器解析HTML代碼的時候,是自上而下執(zhí)行的。
將js文件插入HTML頭部,解析js代碼的時候,無法解析到body里面的代碼,因此找不到要操作的數(shù)據(jù)對象。

此時,需要重新排序,把js代碼放在body的后面。(js代碼可以放在HTML代碼的任意位置)文章來源地址http://www.zghlxwxcb.cn/news/detail-573931.html

到了這里,關(guān)于JS常見報錯解決辦法:Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • vue 啟動項目報錯:TypeError: Cannot set property ‘parent‘ of undefined異常解決

    vue 啟動項目報錯:TypeError: Cannot set property ‘parent‘ of undefined異常解決

    場景:從git上面拉下來一個項目 npm i 下載完依賴以后 npm run serve 去運(yùn)行項目的時候 報錯TypeError: Cannot set property ‘parent’ of undefined 如圖所示 原因:首先排查發(fā)現(xiàn)判斷得出是less解析失敗導(dǎo)致 但是經(jīng)過長時間的查詢解決方案發(fā)現(xiàn)是因為vue版本在下載包的過程中由2.6.10升級為2

    2024年02月12日
    瀏覽(26)
  • Uncaught TypeError: Cannot read properties of undefined (reading ‘remove‘)

    在Vue 3中,你可能會遇到“Uncaught TypeError: Cannot read properties of undefined (reading \\\'remove\\\')”這樣的錯誤,這通常是因為在組件銷毀時,嘗試訪問已經(jīng)被銷毀的元素或事件監(jiān)聽器。 為了解決這個問題,你可以在組件銷毀之前,確保移除所有的事件監(jiān)聽器和其他可能導(dǎo)致問題的操作。

    2024年01月20日
    瀏覽(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:報錯的原因 文檔的加載過程是自上向下加載。使用未命名的變量、會報錯 3;解決辦法 1、將Javascript代碼從標(biāo)簽中放入body中 2、 window.onload = function(){}框起來

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

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

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

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

    報錯:Uncaught TypeError: Cannot read properties of undefined (reading ‘use’) 原因:Vue-router版本問題,在vue-router3可在router/index.js中安裝router插件,但4不支持 解決: 1、在router/index.js中,導(dǎo)出{createRouter, createWebHistory}兩個函數(shù) 使用createRouter來創(chuàng)建路由對象 使用createWebHistory函數(shù)賦值給histor

    2024年02月13日
    瀏覽(43)
  • 【Error】Uncaught TypeError: Cannot read properties of undefined (reading ‘get’)

    【Error】Uncaught TypeError: Cannot read properties of undefined (reading ‘get’)

    報錯原因: 返回值為undefined 解決: vue3可用?

    2024年04月08日
    瀏覽(45)
  • 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版本的時候。只有表頭顯示出來了,內(nèi)容并沒有顯示出來,且報異常。表頭也沒有按照期望的寬度正常顯示。錯誤提示如下 問題原因及解決辦法 該問題出現(xiàn)的原因是因為該表格的表頭涉及到跨行跨列問題,原因是最后一欄出貨記錄的跨列

    2024年02月16日
    瀏覽(26)
  • Uncaught (in promise)和Uncaught (in promise) TypeError: Cannot read properties of undefined (readin

    Uncaught (in promise)和Uncaught (in promise) TypeError: Cannot read properties of undefined (readin

    只要在后面加上.catch((e) = {}),就不會報錯了, ? ?這個問題的解決要想resolve(),在commit()不然就會報錯,注意:先后的順序

    2024年02月09日
    瀏覽(45)
  • Uncaught TypeError: Cannot read properties of null (reading ‘name‘) 和NoSuchMethodException

    Uncaught TypeError: Cannot read properties of null (reading ‘name‘) 和NoSuchMethodException

    分析:這是由于還沒登錄,data.name 還沒獲取到值,所以為null 方法1:可以不管,它不會影響其他功能,當(dāng)你登錄后,便不會報這個錯 方法2:給它一個if判斷是否為null 修改前: 修改后: 修改完后記得先清楚瀏覽器緩存(或換個瀏覽器)再測試。成功解決! 還有一個問題是缺

    2024年02月12日
    瀏覽(19)
  • Uncaught (in promise) TypeError: Cannot read properties of null (reading ‘brands)

    Uncaught (in promise) TypeError: Cannot read properties of null (reading ‘brands)

    在寫vue項目時我們經(jīng)常會遇見這種報錯, 報錯: Uncaught (in promise) TypeError: Cannot read properties of null (reading \\\'brands\\\') 這句話意思是:無法讀取null屬性(讀取\\\'brands\\\') ?解決辦法是在需要渲染的地方加一個v-if來判斷數(shù)據(jù)存在 如下圖 搞定??!?

    2024年02月11日
    瀏覽(31)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包