我正在努力创建比萨店网站。我决定将 id 创建为带有固定导航的 SPA。为了简化我的代码,我在模块中创建了它,但现在我遇到了一个大问题。我如何将模块函数链接到标题中的按钮,因为它会引发错误。在这里我发布了我的代码来演示该错误。为了修复它,我尝试移动部分代码并生成该错误。
<!DOCTYPE html>
<html>
<head>
<title>
Mafia pizza
</title>
<link href="./css/styles.css" rel="stylesheet">
</head>
<body>
<header>
<button id="mainBtn" onclick="jump('')">
Main
</button>
<button id="allBtn" onclick="jump('#all')">
Catalogue
</button>
<button id="pizzaBtn" onclick="jump('#pizza')">
Pizza
</button>
<button id="sushiBtn" onclick="jump('#sushi')">
Sushi
</button>
<button id="drinkBtn" onclick="jump('#drinks')">
Drinks
</button>
<button id="cartBtn" style="float:right;" onclick="jump('#cart')">
In the cart: <span id="amount">0</span>
</button>
</header>
<!-- CLASS WITH CODE -->
<div id="content" class="content" style="width: 100%; height: 100%;">
</div>
<!-- CLASS WITH CODE. AFTER WRITING TO MOVE TO A JS FILE -->
<script type="module">
import { routes } from './js/getpage.js';
import { generatePromo,generateItems } from './js/functions.js';
async function router(){
let link = window.location.href;
let buttonList = document.querySelectorAll('header button');
for(let i=0;i<buttonList.length;i++){
buttonList[i].style.backgroundColor = 'darkorange';
}
慕运维8079593
叮当猫咪
相关分类