在页面数据绑定时,经常会遇到给radio设置选中,以下是我写的js方法,经测试可以使用。欢迎拍砖

<html>
<head>
    <script type="text/javascript" src="./jquery.min.js"></script>
</head>
<body>
<div>
    <input id="rdo1" name="rdo1" type="radio" value="1" checked="checked"/>是
    <input id="rdo1" name="rdo1" type="radio" value="0"/>否

    <button id="btn1">是</button>
    <button id="btn2">否</button>
<div>
<script type="text/javascript">
    $(function(){
        $("#btn1").click(function(){
            $("input[name='rdo1']").eq(0).attr("checked","checked");
            $("input[name='rdo1']").eq(1).removeAttr("checked");
            $("input[name='rdo1']").eq(0).click();
        });
        $("#btn2").click(function(){
            $("input[name='rdo1']").eq(0).removeAttr("checked");
            $("input[name='rdo1']").eq(1).attr("checked","checked");
            $("input[name='rdo1']").eq(1).click();
        });
    });
</script>
</body>
</html>

js设置radio选中的更多相关文章

  1. js设置radio单选框值选中

    html页面: <div> <label><input type="radio" name="sex" value="m ...

  2. 设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选

    设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选 >>>>>>>>>>>>&g ...

  3. js控制radio选中

    经常会遇到js控制radio选中和切换的问题 之前一直使用的是checked属性来完成的 但是现在发现这个属性有个大问题 今天就是用js给选中radio的赋值,使用的$().attr("ch ...

  4. js jquery radio 选中 选中值

    radio示例: <label><input type="radio" name="type" id="type" val ...

  5. 根据JSON的值设置radio选中状态

    说明:页面有一组单选按钮radio,现在页面发送请求得到一组json数据,包括radio的值. 需要根据JSON中的值绑定radio的选中状态> <table class="ta ...

  6. jquery设置radio选中

    <script type="text/javascript"> $(document).ready(function(){ $("input[type=rad ...

  7. 设置radio选中

    选中: $('.viewradio:input[name="istop"][value="' + getSelected().istop + '"]').pro ...

  8. js取消radio选中 反选

    var radio=document.createElement("input");radio.type="radio";radio.onclick = fun ...

  9. js获取radio选中索引值

    <form name="form1" onsubmit="return foo()"> <input type="radio&quo ...

随机推荐

  1. 【高级JEE技术】JMS

    ActiveMQ消息服务器. ActiveMQ是apache的一种jms标准实现,支持两种模型,点对点发送消息以及发布订阅者模型. 为了规范JMS API,JMS为消息传送定义了很多概念: JMS客户 ...

  2. ASP.NET MVC总结

    一.概述 1.单元测试的NUnit, MBUnit, MSTest, XUnit以及其他的框架 2.ASP.NET MVC 应用的默认目录结构有三个顶层目录: Controllers.Models.V ...

  3. ASP.Net Core 运行在Linux(Ubuntu)

    这段时间一直在研究asp.net core部署到linux,今天终于成功了,这里分享一下我的部署过程. Linux Disibutaion:Ubuntu 14.04 Web Server:nginx. ...

  4. hive外部表自动读取文件夹里的数据

    我们在创建表的时候可以指定external关键字创建外部表,外部表对应的文件存储在location指定的目录下,向该目录添加新文件的同时,该表也会读取到该文件(当然文件格式必须跟表定义的一致),删除外 ...

  5. UDP 广播 Java

    1.服务端 public class UdpBroadcastServer { /** * @param args */ public static void main(String[] args) ...

  6. Jsp与servlet之间页面跳转及参数传递实例(转)

    原网址:http://blog.csdn.net/ssy_shandong/article/details/9328985 11. jsp与servlet之间页面跳转及参数传递实例 分类: Java ...

  7. vJine.Core 0.3.0.49 正式发布

    nuget: https://www.nuget.org/packages/vJine.Core/ oschina: http://git.oschina.net/vjine/vJine.Core/a ...

  8. sgu 102 Coprimes

    太水了, 我都不忍心发题解, 但毕竟是sgu上一道题, 我试试能不能一直这么写下去,就是求phi,上代码 #include <cstdio> #include <cstring> ...

  9. 九度OJ 1120 全排列 -- 实现C++STL中next_permutation()

    题目地址:http://ac.jobdu.com/problem.php?pid=1120 题目描述: 给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列. 我们假设对于小写字母有'a' ...

  10. [翻译]log4net教程

    原文:log4net Tutorial 一.基础: log4net分为三部分:配置.设置和调用.配置通常是在app.webconfig或web.config文件中:为了增加灵活性,我们也可以使用单独的 ...