如何在javascript中设置单选按钮 Select 值:

HTML代码:

<input type="radio" name="RBLExperienceApplicable" class="radio" value="1" > 
<input type="radio" name="RBLExperienceApplicable" class="radio" value="0" >


<input type="radio" name="RBLExperienceApplicable2" class="radio" value="1" > 
<input type="radio" name="RBLExperienceApplicable2" class="radio" value="0" >

ASPX代码

     <asp:RadioButtonList ID="RBLExperienceApplicable" runat="server" class="radio"    RepeatDirection="Horizontal" EnableViewState="false">
            <asp:ListItem Value="1" Text="Yes &nbsp;&nbsp;"></asp:ListItem> 
                <asp:ListItem Value="0" Text="No"></asp:ListItem>
        </asp:RadioButtonList>

     <asp:RadioButtonList ID="RBLExperienceApplicable2" runat="server" class="radio"  RepeatDirection="Horizontal" EnableViewState="false">
            <asp:ListItem Value="1" Text="Yes &nbsp;&nbsp;"></asp:ListItem> 
                <asp:ListItem Value="0" Text="No"></asp:ListItem>
        </asp:RadioButtonList>

//从数据库获取一些代码
//基于DB值,挡路将执行脚本

 <script type="text/javascript">
        RadionButtonSelectedValueSet('1');
 </script>

脚本块:

function RadionButtonSelectedValueSet(SelectdValue) {
    $('#RBLExperienceApplicable').val(SelectdValue);
        //$("input[name='RBLExperienceApplicable']:checked").val(SelectdValue);
}

推荐答案

try

function RadionButtonSelectedValueSet(name, SelectdValue) {
    $('input[name="' + name+ '"][value="' + SelectdValue + '"]').prop('checked', true);
}

还可以在dom ready上调用该方法

<script type="text/javascript">
jQuery(function(){
    RadionButtonSelectedValueSet('RBLExperienceApplicable', '1');
})
</script>

Asp.net相关问答推荐

如何格式化搜索字符串以从 Razor 页表中的多个列返回部分搜索字符串?

Windows 命令行中的/p:是什么意思

如何在 ASP.​NET Core 中使用 jquery

ASP.NET web api 无法获取 application/x-www-form-urlencoded HTTP POST

我应该使用用户名还是用户 ID 来引用 ASP.NET 中经过身份验证的用户

从 RowDataBound 事件的 gridview 从单元格中获取值

我需要更改什么以允许我的 IIS7 ASP.Net 3.5 应用程序创建事件源并将事件记录到 Windows EventLog?

ASP.NET 中的 <% %>(嵌入式代码块)

ASP.NET 中的多选下拉列表

页面在谷歌浏览器中加载两次

将查询参数绑定到 ASP.NET Core 中的模型

将新行添加到数据表的顶部

禁用 web.config 继承?

ASP.Net 无法创建/卷影复制

使用 Web.Config 转换的高级任务

根据条件更改 GridView 行 colored颜色

您可以从 web.config 文件中的其他位置提取 log4net AdoNetAppender 的 connectionString 吗?

如何在服务器控件属性中使用 ASP.NET <%= 标签?

Application_End global.asax

ASP.NET MVC2/3 中runAllManagedModulesForAllRequests的正确用法是什么?