是否可以在“background-color:”中放置一个全局变量,然后用颜色设置该变量?
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var colore = #ff0000;
</script>
<canvas id="nota1" class="Nota"
width="300" height="200"
style="border:3px solid black; background-color:VARIABLE_HERE;">
</canvas>
</body>
</html>
答案 0 :(得分:2)
尝试使用JavaScript
var color = 'black'; // sample only
document.getElementById("nota1").style.backgroundColor = color;
<canvas id="nota1" class="Nota" width="300" height="200" style="border:3px solid black;"></canvas>
您也可以仅使用CSS
<canvas id="nota1" class="Nota" width="300" height="200"></canvas>
#nota1 {
background-color: black; /* sample */
border: 1px solid black; /* sample */
}