0

我试图通过页面上的 java 脚本在 asp:RadioButtonList 中获取当前选定的项目。我已经查找了如何做到这一点,但建议的方法都没有奏效。我正在为 dnn 模块编码。这是我所拥有的:

<script type="text/javascript">
function BeginDownload() {
    var radioObj = document.getElementsByName('<%= SliderStyles.ClientID %>');
    for (var i = 0; i < radioObj.length; ++i ) {
        if (radioObj[i].checked) {
            if (radioObj[i].value == "0") { __doPostBack("ImgDownload", $("#waterwheel-carousel-horizon").CurrentSelectedImg().toString()); }
            else if (radioObj[i].value == "1") { __doPostBack("ImgDownload", $("#slides").CurrentSelectedImg().toString()); }
        }
    }
}

<asp:Label runat="server" Text="Slider Style" Font-Bold="True" />
<asp:RadioButtonList ID="SliderStyles" runat="server" RepeatDirection="Horizontal" OnSelectedIndexChanged="SliderStyle_OnSelectedIndexChanged" AutoPostBack="True">
    <asp:ListItem Text="Default" Value="0" Selected="True"></asp:ListItem>
    <asp:ListItem Text="Slide Show" Value="1"></asp:ListItem>
</asp:RadioButtonList>

到目前为止,我在 Javascript 中获得的值每次都返回 null。

4

2 回答 2

0

您的 for 循环不正确,像这样将“++i”更改为“i++”

for (var i = 0; i < radioObj.length; i++ )

于 2012-06-22T21:02:56.350 回答
0
Hello try with getElementsById

<script type="text/javascript">
function BeginDownload() {
    var radioObj = document.getElementsById('<%= SliderStyles.ClientID %>');
    for (var i = 0; i < radioObj.length; ++i ) {
        if (radioObj[i].checked) {
            if (radioObj[i].value == "0") { __doPostBack("ImgDownload", $("#waterwheel-carousel-horizon").CurrentSelectedImg().toString()); }
            else if (radioObj[i].value == "1") { __doPostBack("ImgDownload", $("#slides").CurrentSelectedImg().toString()); }
        }
    }
}
于 2012-06-22T20:54:00.357 回答