亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用數據屬性動態加載腳本

使用數據屬性動態加載腳本

慕森卡 2023-03-18 17:50:30
我想動態加載這個腳本,它包含數據屬性<script class="podigee-podcast-player"   src="https://cdn.podigee.com/podcast-player/javascripts/podigee-podcast-player.js" data-configuration="https://pt.podigee.io/embed?context=external"></script>我試過了。但這對我不起作用。這是設置數據配置屬性的正確方法嗎?我在哪里犯錯?var script = document.createElement('script'); script.type = 'text/javascript';script.async = true;script.src = 'https://cdn.podigee.com/podcast-player/javascripts/podigee-podcast-player.js';script.class = 'podigee-podcast-player';script.dataset.configuration = 'https://pt.podigee.io/embed?context=external';var s = document.getElementsByTagName("body")[0].appendChild(script, s);
查看完整描述

2 回答

?
MM們

TA貢獻1886條經驗 獲得超2個贊

設置數據屬性不是這里的實際問題,但您試圖錯誤地設置類(這似乎很重要)。

那部分需要script.className = 'podigee-podcast-player';


查看完整回答
反對 回復 2023-03-18
?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

當你打字時

var s = document.getElementsByTagName("body")[0].appendChild(script, s);

調用時方法s中的參數不appendChild()存在。appendChild()appendChild()只需要子元素作為參數。嘗試做

var s = document.getElementsByTagName("body")[0].appendChild(script);

var s = 此外,如果您計劃使用返回的值,則只需要鍵入appendChild(),根據文檔,返回值是子元素本身。


查看完整回答
反對 回復 2023-03-18
  • 2 回答
  • 0 關注
  • 99 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號