0

这是 myFunctions 代码,但它不起作用。实际上它的初学者代码是因为我自学了我能做的事情。所有变量都在函数之前声明

原始编码已编辑。

它一直持续到我所拥有的表格中的所有管道尺寸和重量都被填满。它仅在我有 1 个 if 语句时才有效。猜猜我问的是它有什么问题。有没有更简单的方法来做到这一点。我有更多用于不同事物的表格,例如井筒套管。

这行不通

<head>
    <title>Well Service Prevention</title>
    <script>
        var tubingSize;
        var tubingWeight;
        var tubingDisplacement;
        var tubingCapacity;
        function tubingTables(frm){
            if (frm.tubingSize.value == 50.8){
                tubingSize = 50.8
                tubingWeight = 5.06
                tubingDisplacement = 0.00065
                tubingCapacity = 0.001413
                alert("Tubing ID: " + tubingSize)
            }
            if (frm.tubingSize.value == 52.4){
                tubingSize = 52.4
                tubingWeight = 4.84
                tubingDisplacement = 0.000622
                tubingCapacity = 0.001554
                alert("Tubing ID: " + tubingSize)
            }
            if (frm.tubingSize.value == 60.3 && frm.tubingWeight.value == 5.95){
                tubingSize = 60.3
                tubingWeight = 5.95
                tubingDisplacement = 0.000765
                tubingCapacity = 0.00211
                alert("Tubing ID: " + tubingSize "Tubing Weight:" + tubingWeight)
            }
        }
    </script>

</head>
<body>
    <form name=known>
        <h3>
            Enter Known
        </h3>
        <p>Tubing ID: <input type="number" name="tubingSize">
        <p>Tubing Weight: <input type="number" name="tubingWeight">
        <p>Tubing Displacement: <input type="number" name="tubingDisplacement">
        <p>Tubing Capacity: <input type="number" name="tubingCapacity">
        <input type="button" value="Debug" onclick="tubingTables(this.form)">
    </form>
</body>

删除最后一个 if 语句它有效。

<head>
    <title>Well Service Prevention</title>
    <script>
        var tubingSize;
        var tubingWeight;
        var tubingDisplacement;
        var tubingCapacity;
        function tubingTables(frm){
            if (frm.tubingSize.value == 50.8){
                tubingSize = 50.8
                tubingWeight = 5.06
                tubingDisplacement = 0.00065
                tubingCapacity = 0.001413
                alert("Tubing ID: " + tubingSize)
            }
            if (frm.tubingSize.value == 52.4){
                tubingSize = 52.4
                tubingWeight = 4.84
                tubingDisplacement = 0.000622
                tubingCapacity = 0.001554
                alert("Tubing ID: " + tubingSize)
            }
        }
    </script>

</head>
<body>
    <form name=known>
        <h3>
            Enter Known
        </h3>
        <p>Tubing ID: <input type="number" name="tubingSize">
        <p>Tubing Weight: <input type="number" name="tubingWeight">
        <p>Tubing Displacement: <input type="number" name="tubingDisplacement">
        <p>Tubing Capacity: <input type="number" name="tubingCapacity">
        <input type="button" value="Debug" onclick="tubingTables(this.form)">
    </form>
</body>

现在也在努力在 Firefox 中获取调试器。有什么建议吗?

4

1 回答 1

0

你犯了一些错误。这里看看

// frm seems to be a Javascript Object
// tubingSize is a property of frm and seems to be an object too since you are accessing value property of it.
if (frm.tubingSize.value == 52.4){
      tubingSize = 52.4
      tubingWeight = 4.84
      tubingDisplacement = 0.000622
      tubingCapacity = 0.001554
      alert("Tubing ID: " + tubingSize) //debug
}

// Since frm.tubingSize is an object. Either you should do .value here or correct your code in above if.
if (frm.tubingSize == 60.3 && frm.tubingWeight == 5.95){
      tubingSize = 60.3
      tubingWeight = 5.95
      tubingDisplacement = 0.000765
      tubingCapacity = 0.00211
      alert("Tubing ID: " + tubingSize "Tubing Weight:" + tubingWeight)
}

这就是为什么您唯一的一个 IF 正在工作的原因。您也应该在其他 IF 中使用 frm.tubingSize.value。

于 2013-04-07T01:53:11.003 回答