简体   繁体   English

在当地工作。 但是当我使用包裹 index.html 它不是

[英]Locally working. But when i use parcel index.html it's not

I have a pricing page where I have a toggle to switch between annual and monthly.我有一个定价页面,可以在其中切换年度和月度之间的切换。 At the end, I am linking to a js file like this.最后,我链接到这样的 js 文件。

    <div class="top">
          <div class="toggle-btn">
            <span style="margin: 0.8em;">Annually</span>
            <label class="switch">
              <input type="checkbox" id="checbox" onclick="check()" ; />
              <span class="slider round"></span>
            </label>
            <span style="margin: 0.8em;">Monthly</span></div>
        </div>

<header><h2><em>Hobbyist</em></h2>
  <p class="pricing text1">$2 per month</p>  
  <p class="pricing text2">$1 per month billed yearly</p>
 </header>
  

   <script src="js/pricing.js"></script>
    <script src="js/main.js"></script>

And pricing js looks like this定价js看起来像这样


function check() {
  var checkBox = document.getElementById("checbox");
  var text1 = document.getElementsByClassName("text1");
  var text2 = document.getElementsByClassName("text2");
  for (var i = 0; i < text1.length; i++) {
    if (checkBox.checked == true) {
      text1[i].style.display = "block";
      text2[i].style.display = "none";
    } else if (checkBox.checked == false) {
      text1[i].style.display = "none";
      text2[i].style.display = "block";
    }
  }
}


I'm getting an error in the console as a result the toggle is moving but not kicking in the required javascript function that makes the pricing move between $1 and $2 dollars.我在控制台中遇到错误,因为切换正在移动,但没有启动所需的 javascript 函数,这使得定价在 1 美元到 2 美元之间波动。 Can someone suggest me how to fix this?有人可以建议我如何解决这个问题吗? I'm quite new to programming.我对编程很陌生。

Error错误

    Uncaught ReferenceError: check is not defined
    at HTMLInputElement.onclick ((index):74:74)


 Pricing.js function check() { var checkBox = document.getElementById("checbox"); var text1 = document.getElementsByClassName("text1"); var text2 = document.getElementsByClassName("text2"); for (var i = 0; i < text1.length; i++) { if (checkBox.checked == true) { text1[i].style.display = "block"; text2[i].style.display = "none"; } else if (checkBox.checked == false) { text1[i].style.display = "none"; text2[i].style.display = "block"; } } }
 <!DOCTYPE html> <html> <head> <script src="pricing.js"></script> </head> <body> <div class="top"> <div class="toggle-btn"> <span style="margin: 0.8em;">Annually</span> <label class="switch"> <input type="checkbox" id="checbox" onclick="check()" ; /> <span class="slider round"></span> </label> <span style="margin: 0.8em;">Monthly</span></div> </div> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用“parcel index.html”后外部 .js 不起作用 - external .js not working after using “parcel index.html” 使用 `grunt serve` 的页面,但在我加载 index.html 时不会 - Page working with `grunt serve` but not when I load index.html npm run dev 和 parcel index.html 的区别 - Difference between npm run dev and parcel index.html @parcel/core: 无法解析“index.html”得到这个错误 - @parcel/core: Failed to resolve 'index.html' Getting this error 通过启动外部文件 index.html I 忽略主文件,服务器在包裹中运行错误,但它也不起作用(构建失败) - Server running error in parcel by starting the external file index.html I Ignoring the main but it also doesn't work(Build Failed) Vite 预览可以运行,但打开 index.html 时我看不到它正在运行 - Vite preview is working but I can not see it running when opening index.html ionic 2如何在index.html中使用常量变量的声明? - ionic 2 how to use constants variable's declare in index.html? 当我直接单击index.html时,聚合物不起作用 - polymer does not work when i click on index.html directly 使用webpack时如何移动“index.html”? - How can I move “index.html” when using webpack? 当我更改服务器 index.html 文件的方式时,哪些路径不起作用? - What aren't my paths working when I change the way I server my index.html file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM