当前位置: 首页 > 知识库问答 >
问题:

基于变量的不同页面交付[重复]

赵渊
2023-03-14

我有一个相对简单的html/javascript文档,其中包含两种可能的结果(仅使用

     <!doctype html>

<html lang="en">

<head>
    <meta charset="utf-8">

    <title>Fielder's Choice Spinner</title>

    <meta name="description" content="Instore spinner for FC">
    <meta name="author" content="Matthew Davis">

    <link href="style.css" rel="stylesheet">  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <!--ill just leave this here-->

    <script language="JavaScript">
        var response = (function getRandomIntInclusive(min, max) {
  min = Math.ceil(1);
  max = Math.floor(1000);
  return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive 
})();

        document.write(response)

        function script() {
            if (response == 1000) {
                window.location.replace("freeorder.html")
            } 
            if (999 >= response >= 950){
                window.location.replace("15offorder/15offorder.html")
            }
            if (949 >= response >= 849){
                window.location.replace("20offnext.html")
            }
            if (848 >= response >= 698){
                window.location.replace("keychain.html")
            }
            if (697 >= response >= 497){
                window.location.replace("freebaseball.html")
            }
            if (496 >= response >= 396){
                window.location.replace("nospin1.html")
            }
            if (395 >= response >= 295){
                window.location.replace("nospin2.html")
            }
            if (294 >= response >= 1){
                window.location.replace("stamp.html")
            }
        }
        </script>
</head>

<body>

    <button id="link">Link</button>

    <script>
        document.getElementById('link').onclick = function () {
           script();
    };
    </script>

</body>

</html>

但是,现在按钮仅在满足stamp的条件时重定向。实现html并按下按钮。所有其他结果按钮不起任何作用。浏览器开发人员控制台中没有错误。这是“如果”语句的问题还是其他问题?

干杯马特

共有1个答案

耿和韵
2023-03-14

这就是你的问题:

 294 >= response >= 1

评估结果如下:

 (294 >= response) >= 1

因此:

resp = 10
(294 >= 10) == true
true >= 1 // this evaluates to true

但这不适用于您的其他if语句:

999 >= response >= 950

response = 960
999 >= 960 === true 
true >= 950 === false

因此永远不要落入这个if语句中。

你需要做2个明确的检查:

if (999 >= response && response >= 950)
 类似资料:
  • 问题内容: 我的印象是,尽管语法有所不同,但下面的函数a和b在逻辑上是等效的。但是,它们不是,我也不了解它们之间的区别。 在我看来,他们俩都在分配: x对变量z的值, y的值对应于变量x,并且 x + y的值等于变量y。 有人能帮助消除我对多变量分配以及函数a和函数b之间的逻辑差异的误解吗? 问题答案: 分配可以认为是“原子”操作。也就是说,认为在所有操作完成之前,“ 左侧”的所有值都是“冻结”的

  • 我试图根据某个变量调用某些函数。如果我有很多基于这个变量的函数,它很快就会变得非常难看。我的问题是,是否有比做下面的代码更优雅、更“蟒蛇”的解决方案?

  • 问题内容: 我的AngularJS应用程序中有一个页面,我想在其中包含相同的html部分,但具有不同的变量。如果我在我的主要这样做: 而看起来像 两者都会看起来像 我想这与以下事实有关:ng-includes也需要相同的名称。那么,如何将不同的变量发送到每个不同的include? 问题答案: 每次加载新的部分时,传递给的表达式都会求值。在这种情况下,您将值更改为两次,因此在加载两个部分时,当前值将

  • 我提出了以下解决方案: 创建表<代码>记录器<代码>(<代码>id<代码>int(11)NOT NULL AUTO\u INCREMENT,<代码>ip<代码>int(11)NOT NULL,<代码>landing<代码>varchar(16)DEFAULT NULL,<代码>updated<代码>timestamp NOT NULL DEFAULT CURRENT\u timestamp ON

  • C:\python27\arcgis10.1;C:\python27\arcgis10.1\scripts;C:\python27\arcgis10.1\lib\site-packages\osgeo;C:\program Files(x86)\common Files\intergraph\grid Analysis sdk\1.0\program;%systemroot%\systemroot

  • 我有一个类(消息),它有一些实例变量。其中一个变量的类型是interface(MessageContent)。在将这个类序列化为json的过程中,我希望使用依赖于实现的名称序列化这个变量(内容)。下面是详细信息的代码片段: 我的要求是,当消息序列化并且内容类型为VideoMessage时,序列化的json应该是: 如何通过fasterxml Jackson实现?我正在使用ObjectMapper的