zoukankan      html  css  js  c++  java
  • jQuery获取及设置单选框、多选框、文本框

    获取一组radio被选中项的值 
    var item = $("input[@name=items][@checked]").val(); 
    获取select被选中项的文本 
    var item = $("select[@name=items] option[@selected]").text(); 
    select下拉框的第二个元素为当前选中值 
    $("#select_id")[0].selectedIndex = 1; 
    radio单选组的第二个元素为当前选中值 
    $("input[@name=items]").get(1).checked = true;

    获取值:

    文本框,文本区域:$("#txt").attr("value"); 
    多选框checkbox:$("#checkbox_id").attr("value"); 
    单选组radio: $("input[@type=radio][@checked]").val(); 
    下拉框select: $("#sel").val();

    控制表单元素: 

    文本框,文本区域:$("#txt").attr("value","");//清空内容 
    $("#txt").attr("value","11");//填充内容

    多选框checkbox: $("#chk1").attr("checked","");//不打勾 

    $("#chk2").attr("checked",true);//打勾 
    if($("#chk1").attr("checked")==undefined) //判断是否已经打勾

    单选组radio: $("input[@type=radio]").attr("checked","2");//设置value=2的项目为当前选中项 (错


    $("input[@name=radio_s][@value=16]").attr("checked",true);(测试通过) 

    下拉框select:

    $("#sel").attr("value","-sel3");//设置value=-sel3的项目为当前选中项 
    $("11112222").appendTo("#sel")//添加下拉框的option 
    $("#sel").empty();//清空下拉框

    $("#select1")[0].options(index).selected = true; //使第index个option选中
    $("#select1")[0].options(3).text //取索引为3的option值

     
     
    ===================================另一篇文章==================================
    $(document).ready(function() {      $("#btnSubmit").click(function() {          alert($("input[name='RadioButtonList1']:checked").val());      });  });   <asp:RadioButtonList ID="RadioButtonList1"runat="server"><asp:ListItem>1</asp:ListItem><asp:ListItem>2</asp:ListItem><asp:ListItem>3</asp:ListItem></asp:RadioButtonList><input id="btnSubmit"type="button"value="Submit"/>
  • 相关阅读:
    HDU 5583 Kingdom of Black and White 水题
    HDU 5578 Friendship of Frog 水题
    Codeforces Round #190 (Div. 2) E. Ciel the Commander 点分治
    hdu 5594 ZYB's Prime 最大流
    hdu 5593 ZYB's Tree 树形dp
    hdu 5592 ZYB's Game 树状数组
    hdu 5591 ZYB's Game 博弈论
    HDU 5590 ZYB's Biology 水题
    cdoj 1256 昊昊爱运动 预处理/前缀和
    cdoj 1255 斓少摘苹果 贪心
  • 原文地址:https://www.cnblogs.com/ken-admin/p/5826597.html
Copyright © 2011-2022 走看看