zoukankan      html  css  js  c++  java
  • jquery对radio和checkbox的操作

    jQuery获取Radio选择的Value值

    代码
     $("input[name='radio_name'][checked]").val(); //选择被选中Radio的Value值
     $("#text_id").focus(function(){//code...}); //事件 当对象text_id获取焦点时触发
     $("#text_id").blur(function(){//code...}); //事件 当对象text_id失去焦点时触发
     $("#text_id").select(); //使文本框的Vlaue值成选中状态
    $("input[name='radio_name'][value='要选中Radio的Value值'").
    attr("checked",true); //根据Value值设置Radio为选中状态

    jQuery获取CheckBox选择的Value值

    $("input[name='checkbox_name'][checked]"); //选择被选中CheckBox元素的集合 如果你想得到
    Value值你需要遍历这个集合
    $($("input[name='checkbox_name'][checked]")).
    each(function(){arrChk+=this.value + ',';});//遍历被选中CheckBox元素的集合 得到Value值
    $("#checkbox_id").attr("checked"); //获取一个CheckBox的状态(有没有被选中,返回true/false)
    $("#checkbox_id").attr("checked",true); //设置一个CheckBox的状态为选中(checked=true)
    $("#checkbox_id").attr("checked",false); //设置一个CheckBox的状态为不选中(checked=false)
    $("input[name='checkbox_name']").attr
    ("checked",$("#checkbox_id").attr("checked"));//根据3,4,5条,你可以分析分析这句代码的意思
    $("#text_id").val().split(","); //将Text的Value值以','分隔 返回一个数组
  • 相关阅读:
    STL源码剖析:迭代器
    STL源码剖析:配置器
    [bzoj3940][Usaco2015 Feb]Censoring
    [bzoj2212][Poi2011]Tree Rotations
    [bzoj2733]永无乡&&[bzoj3545]Peaks
    挂个AC自动机
    [bzoj4237]稻草人
    莫比乌斯反演定理证明
    斜率优化dp学习
    备忘
  • 原文地址:https://www.cnblogs.com/deepbreath/p/4482758.html
Copyright © 2011-2022 走看看