gpt4 book ai didi

javascript - 通过 JavaScript 在 ins 标签内更改值

转载 作者:行者123 更新时间:2023-12-04 16:15:00 28 4
gpt4 key购买 nike

<ins class='adsbygoogle'
style='display:block'
data-ad-client='ca-pub-XXXXXXXXXXXXXXX'
data-ad-slot='000000000000'
data-ad-format='auto'
data-full-width-responsive='true'></ins>
我想用 JavaScript 将 data-ad-slot 值更改为 123456789。我怎样才能做到这一点?
我试过这个~(但不工作)

<ins class='adsbygoogle'
style='display:block'
data-ad-client='ca-pub-XXXXXXXXXXXXXXX'
data-ad-slot=document.write (x);
data-ad-format='auto'
data-full-width-responsive='true'></ins>

<script> var x= 123456789;</script>

最佳答案

设置 .dataset.adSlot

<ins class='adsbygoogle'
style='display:block'
data-ad-client='ca-pub-XXXXXXXXXXXXXXX'
data-ad-format='auto'
data-full-width-responsive='true'></ins>
<script>
var x= 123456789;
var elem = document.querySelector('.adsbygoogle');
elem.dataset.adSlot = x;
console.log(elem);
</script>

关于javascript - 通过 JavaScript 在 ins 标签内更改值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63179604/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com