0

我正在使用带有单位转换器的开关功能,允许用户交换单位而不是更改他们的选择。它工作正常,然后我注意到在某些情况下它失败了。

我经历了所有选项,直到减小值字段的大小/然后才起作用。我认为该值太长,但在这里检查后:

HTML 属性值的最大长度

看起来我在界限之内。所以我想知道它还能是什么?

下面是从控制台日志中获取的两个示例,显示了按下切换按钮之前和之后以及我更改名称后的结果。

Measurement Type: thermalExpansion
convertFunctions.js:30BEFORE!!! from:  length/length/degreeC to:  length/length/degreeRan
convertFunctions.js:40AFTER!!! from:  length/length/degreeC to:  length/length/degreeRan
convertFunctions.js:1020Parsed input is 1 and result is 0.555555556

Measurement Type: thermalExpansion
convertFunctions.js:30BEFORE!!! from:  lengthRan to:  lengthk
convertFunctions.js:40AFTER!!! from:  lengthk to:  lengthRan

编辑:我刚刚在现场使用斜线再次测试,但失败了。

再次编辑:更多信息:

该函数显示控制台日志的生成位置

function switchUnits(){

//need to get values before swap to and from around.
var from = $("#from").val();
var to = $("#to").val();
console.log('BEFORE!!! from: ', from, 'to: ', to );

//switches the details
$("#to #"+from).attr("selected","selected");
$("#from #"+to).attr("selected","selected");

//gets values after switch
from = $("#from").val();
to = $("#to").val();

console.log('AFTER!!! from: ', from, 'to: ', to );

//run convert
convertUnits();
}

已编辑 JSON 文件以从值字段中删除所有“/”的示例

编辑示例之前:

   "thermalExpansion":[
    {
        "value": "length/degreek",
        "name" : "Length / Length / Kelvin (1/K)"
    },

],

编辑示例后:

   "thermalExpansion":[
    {
        "value": "lengthk",
        "name" : "Length / Length / Kelvin (1/K)"
    }
],
4

0 回答 0