我正在尝试通过页面上的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。
答案 0 :(得分: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()); }
}
}
}
答案 1 :(得分:0)
你的for循环不正确将“++ i”更改为“i ++”,如下所示
for(var i = 0; i&lt; radioObj.length; i ++)