【问题标题】:Set values (and text) of items of asp.net Radio Button List using JQuery使用 JQuery 设置 asp.net 单选按钮列表项的值(和文本)
【发布时间】:2014-08-26 14:31:18
【问题描述】:

我正在尝试使用 JQuery 设置 asp.net 单选按钮列表项的值(和文本)。我正在尝试选择 RBL 项目的索引并设置它们的值和文本。我尝试了各种变体但没有成功。请提供任何帮助。以下是我的标记。

<body>
<form id="form1" runat="server">
<div>
    <asp:RadioButtonList ID="RBL" runat="server" ClientIDMode="Static">
        <asp:ListItem></asp:ListItem>
        <asp:ListItem></asp:ListItem>
        <asp:ListItem></asp:ListItem>
        <asp:ListItem></asp:ListItem>
    </asp:RadioButtonList>
</div>
</form>

<head runat="server">
  <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
 <script type="text/javascript">
$(document).ready(
function() {
    $($('#RBL').get[1]).val('One');
    $($('#RBL').index(2)).val('Two');
    $($('#RBL')[3]).val('Value');
});

【问题讨论】:

    标签: jquery asp.net


    【解决方案1】:

    我建议走这条路:

    js

    $(document).ready(function () {
    
        var values = ["One","Two","three", "four"];
    
        $("#RBL").children().find("input:radio").each(function (i, e) {
            e.value = values[i];
            e.innerHTML = values[i];
            i++;
        });
    
    });
    

    使用您想要的值创建一个数组并将它们传递到您的收音机。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      相关资源
      最近更新 更多