Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
两个颜色值一个用于h1标题,一个用于html和javascript背景_Javascript_Html_Css - Fatal编程技术网

两个颜色值一个用于h1标题,一个用于html和javascript背景

两个颜色值一个用于h1标题,一个用于html和javascript背景,javascript,html,css,Javascript,Html,Css,我需要保存两个值,一个用于h1标签,另一个用于身体背景。我现在让用户选择颜色1和颜色2。当我按下第三个按钮时,所有更改都必须应用,并且颜色必须更改,但没有运气:( (html) 你唯一做错的事情就是没有将它分配到正确的变量 工作代码在下面 函数myFunction(){ var matches=document.querySelector(“h1”); var button0=document.getElementById(“kleur0”).value; //var matches=docu

我需要保存两个值,一个用于h1标签,另一个用于身体背景。我现在让用户选择颜色1和颜色2。当我按下第三个按钮时,所有更改都必须应用,并且颜色必须更改,但没有运气:(

(html)


你唯一做错的事情就是没有将它分配到正确的变量

工作代码在下面

函数myFunction(){
var matches=document.querySelector(“h1”);
var button0=document.getElementById(“kleur0”).value;
//var matches=document.querySelector(“.h1tag”);
var button1=document.getElementById(“kleur1”).value;
document.body.style.backgroundColor=按钮0;
matches.style.color=按钮1;
}
0
我需要保存两个值,一个用于h1标签,另一个用于身体背景。我现在让用户选择颜色1和颜色2。当我按下第三个按钮时,所有更改都必须应用,并且颜色必须更改,但没有运气:(
(html)
所有元素
    这是我的书名
  • 第1段:第1段
  • 第2段:en ik nam mee
  • 第3段:即使是stekkerdoos
  • 第4段:恩恩扎克兰普
阿赫特格罗德·克勒奥普斯兰 克勒奥普斯兰酒店 克莱伦·托帕森帕吉纳酒店
您好,您遇到了什么错误?我看到您在函数中忘记了“f”,这可能是问题所在吗?如果不是,我建议您使用这里的示例,请注意h1有一个用于在js代码中引用它的类名感谢您的快速回复我的代码现在运行良好:)
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>All the elements</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>


    <div class="h1tag">

<ul>
    <h1> dit is een title</h1>
    <li>paragraaf 1: Ik ging op reis</li>
    <li>paragraaf 2: en ik nam mee</li>
    <li>paragraaf 3: een stekkerdoos</li>
    <li>paragraaf 4: en een zaklamp</li>


</ul>
</div>




        <button type="button" onclick="saveUserData()"class="button0">achtergrond kleur opslaan</button>
        <input id="kleur0" type="color" value="#ff0000">

        <button type="button" onclick="saveUserdata()"class="button1">titel kleur opslaan</button>
        <input id="kleur1" type="color" value="#ff0000">

        <button onclick="myFunction()">kleuren toepassen op pagina</button>

    </body>




<footer>
<script defer src="script.js"></script>
</footer>
</html>
unction myFunction(){ 
var matches = document.querySelector(".h1");
var button0 = document.getElementById("kleur0").value;

var matches = document.querySelector(".h1tag");
var button1 = document.getElementById("kleur1").value;

return document.body.style.backgroundColor = kleur0.kleur1;
}