zoukankan      html  css  js  c++  java
  • jquery获取和设置radio,check,select选项(转)

    select控件选项

    1,获取select选中的value值

          $("#selectID").val();

    2,获取select选中的text的值

     $("#selectID").find("option:selected").text()

    3,设置select的第几项为当前选中项

    $("#selectID").attr("value",2);//设置第二项为当前选中项

    4,添加option

    $("selectID").append("<option value='5'>select5</option>");

    5,删除一项option

    $("#SelectID option[value='3']").remove();  //删除Select中Value='3'的Option

    6.,获取Select选择的索引值 

    var checkIndex=$("#selectID ").get(0).selectedIndex;  //获取Select选择的索引值 

    7,删除所有项

    $("#SelectID").remove();

     

    checkbox控件的使用

    1,获取checkbox的value

    $("#checkboxID").value或$("input[type='checkbox']").eq(n).attr("checked").value

    2,设置选中项

    $("input[type='checkbox']").eq(1).attr("checked")//设置第一个checkbox为选中的项

    3,删除所有checkbox

      $("input[type='checkbox']").remove()

    4,checkbox方法

      $(document).ready(function() {
            var check = $("input[type='checkbox']");
            check.each(function(n) {
            check.eq(n).bind("click", function() {
             
                    if (check.eq(n).attr("checked") != false) {
                        var value = check.eq(n).val();
                        alert(value);
                    }
                    else {
                        alert(check.eq(n).attr("checked"));
                    }
                })
            });
        });

    radio控件

    1,获取选中的value值

    $("input[type='radio']:checked").val();

    2,设置指定的项为当前选中项

      $("input[type='radio']").eq(1).attr("checked",true);//设置第二项为选中项

  • 相关阅读:
    Big Number
    Who will be punished
    find your present (2)
    Being a Good Boy in Spring Festival
    day4__列表的初识(列表的创建、增删改查、元组、range)
    day3、基础___(基础数字类型、字符串索引与切片、str常用操作方法)
    day2、基础__(while循环、格式化输出、运算符、初始编码)
    day1: 基础 __ (变量、常量、注释、数据类型、input、 if)
    十八、FTP配置
    十七、交换机配置管理IP和telnet登陆设置
  • 原文地址:https://www.cnblogs.com/zhwl/p/1978109.html
Copyright © 2011-2022 走看看