我在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;

08-25 13:36
查看更多