javascript SWITCH语句不触发

标签 javascript

我在 ASP.NET C# Web 应用程序的 javascript 中有一个 switch 语句。我正在用 FireBug 调试它,它出错了:它一到达 switch 就立即存在。

代码如下:

$(function() {

    $('#received_dateTextbox').mask("99/99/99");
    $('#report_dateTextBox').mask("99/99/99");
    $('#occurrence_dateTextBox').mask("99/99/99");

    //var checkValues='';

    $('table input:checkbox').click(function() {

        if ($(this).prop('checked')) {
            var checkText = $(this).next('a').text();
            var hrefValue = $(this).next('a').attr('href');
            var trimIndex = hrefValue.lastIndexOf('\\') + 1;
            var checkValue =  hrefValue.substr(trimIndex, hrefValue.indexOf("')",trimIndex)-trimIndex);

            //checkValues+=checkValue+";";

            switch(checkValue)
            {
                //preanalytical other
                case "21": 
                    var userInput = prompt("Other:", "Other:");
                    $(this).next('a').html('Other:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //analytical other
                case "53": 
                    var userInput = prompt("Other:", "Other:");
                    $(this).next('a').html('Other:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //postanalytical other
                case "89": 
                    var userInput = prompt("Other:", "Other:");
                    $(this).next('a').html('Other:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //other other
                case "95": 
                    var userInput = prompt("Other:", "Other:");
                    $(this).next('a').html('Other:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //analytical liquid handler instrument failure
                case "40":
                    var userInput = prompt("Liquid Handler#:", "Liquid Handler#:");
                    $(this).next('a').html('Liquid Handler#:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //analytical olympus instrument failure
                case "41":                   
                    var userInput = prompt("Olympus#:", "Olympus#:");
                    $(this).next('a').html('Olympus#:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //analytical lcms instrument failure
                case "42":
                    var userInput = prompt("LC-MS/MS#:", "LC-MS/MS#:");
                    $(this).next('a').html('LC-MS/MS#:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //analytical liquid handler delay prod
                case "49":
                    var userInput = prompt("Liquid Handler#:", "Liquid Handler#:");
                    $(this).next('a').html('Liquid Handler#:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //analytical olympus delay prod
                case "50":
                     var userInput = prompt("Olympus#:", "Olympus#:");
                    $(this).next('a').html('Olympus#:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //analytical lcms delay prod
                case "51":
                    var userInput = prompt("LC-MS/MS#:", "LC-MS/MS#:");
                    $(this).next('a').html('LC-MS/MS#:' + '<font color="red">' + userInput + '</font>');
                    checkValues+=checkValue+":"+userInput;
                break;

                //wrong practice code
                case "63":
                    if (confirm("Do you want to check Report Sent to Wrong Location/Physician?"))
                    { var elNode = document.getElementById("TreeView1n82CheckBox");
                        $(elNode).prop("checked", true);
                     }
                    else
                    { var elNode = document.getElementById("TreeView1n81CheckBox");
                        $(elNode).prop("checked", false);
                    }

                break;  

                default: 
                    alert('no match');                
            }
        }
    });
    //document.getElementById('HiddenField1').value = checkValues;
});

调试器告诉我 checkValue 确实有一个值

我做错了什么?

最佳答案

checkValue 可以存储为数字,而不是所有“大小写”检查的字符串。

检查 case parseInt("95") : ... 是否有效。

此外,如果您向数字添加一个字符,然后检查您的案例是否开始工作,请检查:

switch(checkValue + 'A')

然后 case "53A": .... break;

关于javascript SWITCH语句不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7922288/

相关文章:

javascript - 将 Mat Dialog Angular 4 中的多个数据传递回父级

javascript - 转换来自谷歌驱动器的所有 csvs

javascript - ionic 滚动有白色覆盖层滞后

javascript - 让 Greasemonkey 对元素的 ajax 更改使用react

javascript - 仅当数组元素尚不存在时,如何将其插入数据库

Javascript 文本框按键事件

javascript - 如何将异步回调中的字符串添加到一起?

javascript - React中的({})是什么意思?

javascript - 检测 adblock 和 javascript

javascript - 在 Chartjs 中让折线图*向上*到 1 时出现问题,在*图表线下方*有大填充