English 中文(简体)
我是否正确地在html文件中使用这一共同文件变量?
原标题:Did I use this JS variable correctly in the html document?
<head>
  <script>
    var bgcolor = #ff0000
  </script>
</head>
<body style="background-color: var(--bgcolor);">
</body>

我想使一份联合材料的功能改变某些投入的背景。 我玩弄联合材料的功能,我只能拿“var”在超文本档案中工作。 有些人可以检查我的正确性。

问题回答

虽然变量在名称和使用上相同,但实施这些变量的方式在中央支助事务和 Java之间有所不同。 它们不可互换。 谨请将此文件编成类似文件:

<head>
  <style>
    :root {
      --bgcolor: #ff0000
    }
  </style>
</head>
<body style="background-color: var(--bgcolor);">
</body>

答案是否简短? CSS变量与联合材料变量不同

FYK: 一种很好的替代办法是使用一种DOM方法,但我在此解释说,尽管我并不认为这种方法对本案确实有用(肯定会是后来的o):

PS: I assume you re beginning with js, but I d recommend using let or const to declare variables, I ll let you do some research about that.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签