javascript - 为什么这是未定义的以及如何解决这个问题? C#

标签 javascript c# asp.net visual-studio-2010

我正在创建一个场景,其中多个问题需要 3 个单选按钮。我向单选按钮添加了值,我想将所选单选按钮的总分相加并将其显示到文本框中。

这是我的代码,我很难弄清楚为什么我收到未定义的错误消息。 enter image description here

 function getSelectionPoints(selection) {
        return parseInt(selection.split(",")[1]);
    }

    function getSelectionObj(selectionID) {
        var selection = null;

        if(selectionID == 1)
            selection = document.getElementById("<%=selection1.ClientID %>").getElementsByTagName("input");
        else if (selectionID == 2)
            selection = document.getElementById("<%=selection2.ClientID %>").getElementsByTagName("input");
        else if (selectionID == 3)
            selection = document.getElementById("<%=selection3.ClientID %>").getElementsByTagName("input");

        return selection;
    }

    function getTotalPoints() {
        var totalPoints = 0;
        var selection;
        var promotionDropdown = document.getElementById("<%=dropDownPromotionTo.ClientID %>");
        var promotionFromID = parseInt(document.getElementById("<%=promotionIDFromHidden.ClientID %>").value);
        var promotionToID = parseInt(promotionDropdown.options[promotionDropdown.selectedIndex].value);

        for (var i = 1; i <= 9; i++) {
            selection = getSelectionObj(i);

            if (i == 9 && (promotionFromID == 2 || promotionFromID == 3 || promotionToID == 2 || promotionToID == 3)) {
                totalPoints += 0;
            }

            else if (selection != null) {
                for (var j = 0; j < selection.length; j++) {
                    if (selection[j].checked) {
                        totalPoints += getSelectionPoints(selection[j].value);
                        break;
                    }
                }
            }
        }
        alert(totalpoints); 
        return totalPoints;
    }
    <asp:RadioButtonList ID="selection1" runat="server"
                    EnableTheming="True" SkinID="Black" CausesValidation="True" onchange="updateMyPoints(false, true);">
                        <asp:ListItem Value="1,6">Spectacular</asp:ListItem>
                        <asp:ListItem Value="2,4" Selected="True">Average</asp:ListItem>
                        <asp:ListItem Value="3,0">Needs improvement</asp:ListItem>
                    </asp:RadioButtonList>

最佳答案

JavaScript 区分大小写,请使用 totalPoints 而不是 totalpoints:

alert(totalPoints); 

关于javascript - 为什么这是未定义的以及如何解决这个问题? C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31391638/

相关文章:

c# - 我应该在哪里保存序列化数据文件?

c# - 解码C#中的特殊字符

asp.net - 访问所有事件客户端 session 集合?

c# - HTTPS 自动登录问题

c# - 在测试项目中使用 ASP.NET Core 的 ConfigurationBuilder

javascript - OnTextChanged 函数未触发

javascript - TypeError : key must be a string, 存在 GCP 文件类型错误的缓冲区或对象

javascript - 脚本可以在 jsfiddle 上运行,但不能在网站上运行

JavaScript 数组

javascript - 如何在元素通过过渡重新定位后防止滑动