Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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
Javascript i';我很难在1个html、1个css和1个js中转换1个html文件,有人能帮我一下吗?_Javascript_Html_Css - Fatal编程技术网

Javascript i';我很难在1个html、1个css和1个js中转换1个html文件,有人能帮我一下吗?

Javascript i';我很难在1个html、1个css和1个js中转换1个html文件,有人能帮我一下吗?,javascript,html,css,Javascript,Html,Css,所以我已经开始编写代码了,但我想我是个哑巴,因为我无法拆分这些代码,我希望能得到一些帮助 <html> <head> <title>Exploring HTML</title> <style> body { color: red; } h1 { font-family: Arial, sans-serif; font-size: 32px; color: black; } </style> </head> <

所以我已经开始编写代码了,但我想我是个哑巴,因为我无法拆分这些代码,我希望能得到一些帮助

<html>
<head>
<title>Exploring HTML</title>
<style>
body {
color: red;
}
h1 {
font-family: Arial, sans-serif;
font-size: 32px;
color: black;
}
</style>
</head>
<body>
<h1>My first web page</h1>
<p>This is my first web page, it's a little basic, but it's helping me understand how HTML works and how to markup my content.</p>
<button id="color">Change color!</button>
<script src="js.js">

</script>
</body>
</html>

探索HTML
身体{
颜色:红色;
}
h1{
字体系列:Arial,无衬线;
字体大小:32px;
颜色:黑色;
}
我的第一个网页
这是我的第一个网页,有点基础,但它帮助我理解HTML是如何工作的,以及如何标记我的内容

换颜色!
这些链接可以帮助您获得答案


这就是如何将网页拆分为不同文件的方法。您希望在head标记中使用
链接
,以包含外部CSS文件。对于外部
script
文件,您仍然使用
标记,但不向其插入任何内容,您可以应用
src
属性
标记可以在头部或
主体
标记中,通常最好将其添加到
主体
标记的末尾,以防止渲染阻塞

index.html

<html>
<head>
   <title>Exploring HTML</title>
   <link rel="stylesheet" href="style.css" />
</head>
<body>
   <!-- Body Content -->
   <div id="color">Click Here to Rotate Colors</div>
   <script src="script.js"></script>
</body>
</html>
script.js

body {
   color: red;
}
h1 {
   font-family: Arial, sans-serif;
   font-size: 32px;
   color: black;
}
(function() {
   // Set the variable "node" and set the event listener on click
   var node = document.getElementById('color');
   node.addEventListener('click',changeColor,false);

   function changeColor(e) {
      // Get the target (node) that the user clicked
      var target = e.target || e.srcElement;

      // Get the color from the data-color attribute
      var color = target.getAttribute('data-color');

      // Define the colors to rotate
      var colors = ['red','green','blue'];

      // Get the position of the color. red = 0, green = 1, etc
      var index = colors.indexOf(color);

      // If the index is the last item in the array you want
      // to change the index to 0 otherwise it increases by 1
      var next = (index+1 == colors.length ? 0 : index+1);

      // Set the new color and the data-color attribute
      target.style.color = colors[next];
      target.setAttribute('data-color',colors[next]);   
   }
})();

上述代码的工作示例可在中找到。我之所以设置
data color
而不是读取
style.color
变量,是因为我不确定某些浏览器是否会以不同的方式修改此值。我知道浏览器不会修改
数据颜色属性。

访问此网站。。什么都读不太清楚你是什么asking@gerdi嗯,不。傻瓜们被过度提拔了,但相当垃圾。OP可以在堆栈溢出上找到与此问题相关的所有内容。。好吧,如果你这么说的话。我一直认为学习编程最好的方法就是无休止地滚动浏览questions@nicael-嗯,W3Schools是一个很好的初学者网站,有容易理解的句子和概念()。你应该提供一些链接的上下文,引用相关部分,等等。我已经读过了,但函数没有改变文本的颜色,因为它支持什么文本颜色没有改变?您从来没有问过必须更改文本颜色,只是问过如何分割文件。但是我发送的文件有一个函数,可以将正文从红色更改为绿色在您提供的代码中,没有任何东西可以将颜色从红色更改为绿色。也许你忘了在你的问题中包含一些代码