基本功能JS无法正常工作

时间:2017-10-09 11:59:49

标签: javascript function

我正在寻找加载功能,而我点击按钮。 我正在学习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>

   

1 个答案:

答案 0 :(得分:1)

使用了错误的令牌“”。

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>