gpt4 book ai didi

javascript - 为什么我的代码运行不正确?这个if语句有什么问题?

转载 作者:行者123 更新时间:2023-12-01 03:57:30 25 4
gpt4 key购买 nike

我正在设计一个可以更改价格的网站 当我第一次点击 slider 时,价格变为 19.99,下一次我的价格变为 199.99。我的元素是这个https://www.frontendmentor.io/challenges/pricing-component-with-toggle-8vPwRMIC

我使用变量,如果变量 ==1 则将价格更改为 199.99 ,当变量 ==2 则将价格更改为 19.99 ;但每次我点击价格都保持在 19.99:/

$(function(){
var m = 1;
$(".switch").click(function(){
if(m == 1){
alert("hi");
$("#h1").html("$199.99");
$("#h2").html("$249.99");
$("#h3").html("$399.99");
m = 0;
} else{
alert("bye");
$("#h1").html("$19.99");
$("#h2").html("$24.99");
$("#h3").html("$39.99");
m = 0;
}

});

});

当我点击“嗨”和“再见”警报时,会收到警报,但我不知道为什么???:/// if block 中的 return 语句也不是解决方案,我尝试过。

最佳答案

据我认为价格尚未定义。

关于javascript - 为什么我的代码运行不正确?这个if语句有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61947539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com