标签:class fun get 网页 str text dex 现在 def
这个时候我们出现了一种新的编程方式,叫做面向对象编程
<!DOCTYPE html> <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>这是最原始的网页开发</title> </head> <body> <p>这是我们的网页内容</p> <div id="root"></div> <script src=‘./index.js‘></script> </body> </html>
var dom = document.getElementById(‘root‘); var header = document.createElement(‘div‘); header.innerText = ‘header‘; dom.appendChild(header); var sidebar = document.createElement(‘div‘); sidebar.innerText = ‘sidebar‘; dom.appendChild(sidebar); var content = document.createElement(‘div‘); content.innerText = ‘content‘; dom.appendChild(content);
<!DOCTYPE html> <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>这是最原始的网页开发</title> </head> <body> <p>这是我们的网页内容</p> <div id="root"></div> <script src="./header.js"></script> <script src="./sidebar.js"></script> <script src="./content.js"></script> <script src="./index.js"></script> </body> </html>
header.js
function Header() { var header = document.createElement(‘div‘); header.innerText = ‘header‘; dom.appendChild(header); }
function Sidebar() { var sidebar = document.createElement(‘div‘); sidebar.innerText = ‘sidebar‘; dom.appendChild(sidebar); }
function Content() { var content = document.createElement(‘div‘); content.innerText = ‘content‘; dom.appendChild(content); }
var dom = document.getElementById(‘root‘); new Header(); new Sidebar(); new Content();
<!DOCTYPE html> <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>这是最原始的网页开发</title> </head> <body> <p>这是我们的网页内容</p> <div id="root"></div> <script src="./index.js"></script> </body> </html>
import Header from ‘./header‘; import Sidebar from ‘./sidebar‘; import Content from ‘./content‘; var dom = document.getElementById(‘root‘); new Header(); new Sidebar(); new Content();
npm init 项目名
npm install webpack webpack-cli
npx webpack index.js
标签:class fun get 网页 str text dex 现在 def
原文地址:https://www.cnblogs.com/wzndkj/p/10703905.html