zoukankan      html  css  js  c++  java
  • Jquery Dom节点常用操作

    select 标签

      form提交的时候 提交select标签选中的value值

    1. 添加项

      $("#select_id").append("<option value='Value'>Text</option>");  //添加一项option

      $("#select_id").prepend("<option value='0'>请选择</option>"); //在前面插入一项option

    2. 删除项

      $("#select_id option:first").remove(); //删除第一项

      $("#select_id option:last").remove(); //删除最后一项

      $("#select_id option[index='0']").remove();//删除索引值为0的Option

      $("#select_id option[value='3']").remove(); //删除值为3的Option

      $("#select_id option[text='4']").remove(); //删除TEXT值为4的Option

    3. 清空项

      $("#select_id").empty();

      $("#select_id").html('');

    4. 设置select选中项

      设置select选中的索引

      $("#select_id").get(0).selectedIndex=index;// index为索引值

      设置select 选中的value:

      $("#select_id option[value='value2']").attr("selected", "selected");

        $("#select_id").attr("value","Normal“);

        $("#select_id").val("Normal");

        $("#select_id").get(0).value = value;

      试图设置select的text值都是无效的。

    5. 获取select选中项

      $("#select_id ").val();//获取select 所有的value值

      $("#select_id ").text();//获取select 所有的text值

      $('#select_id option:selected').val();  $('#select_id').find("option:selected").val()//获取select 选中的value值

      $('#select_id option:selected').text();  $('#select_id').find("option:selected").text()//获取select 选中的text值

      $('#select_id').get(0).selectedIndex; //获取select选中的索引

    6. 触发事件

       $('#select_id').change(function () {
                    alert('you click select_id');
                });

    input[type=checkbox] 标签

      form提交的时候 当checkbox被选中时,字段被提交;当checkbox不被选中时,字段不被提交

  • 相关阅读:
    (1)李宏毅深度学习-----机器学习简介
    Git命令之不得不知的git stash暂存命令
    Http2升级方案调研
    神奇的 SQL 之别样的写法 → 行行比较
    熔断机制
    限流算法
    状态机
    布隆过滤器
    负载均衡算法
    K8S Ingress
  • 原文地址:https://www.cnblogs.com/eye-like/p/4323573.html
Copyright © 2011-2022 走看看