gpt4 book ai didi

javascript - JS基本功能不起作用

转载 作者:行者123 更新时间:2023-12-03 03:19:10 30 4
gpt4 key购买 nike

我正在寻找在单击按钮时加载功能。我正在学习 JS ...

function changeStyle(){
var paragraphe = document.getElementById('monParagraphe');
paragraphe.style.backgroundColor="#000";
}

function load(){
var buttonElt = document.getElementsByTagName('button');
buttonElt.addEventListener('click', changeStyle)
}
<p id=’monParagraphe’>Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
</p>

<button onclick=changeStyle()>Changer le style</button>

最佳答案

使用了错误的标记“”。

function changeStyle(){
var paragraphe = document.getElementById('monParagraphe');
paragraphe.style.backgroundColor="#000";
}

function load(){
var buttonElt = document.getElementsByTagName('button');
buttonElt.addEventListener('click', changeStyle)
}
<p id="monParagraphe">Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
</p>

<button onclick="changeStyle()">Changer le style</button>

关于javascript - JS基本功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46645947/

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