• Jquery


    Checkbox

    //判断是否选中
    if ($(this).is(':checked')) 
    { alert(
    "它处于选中状态"); } else
    { alert(
    "它不处于选中状态"); } if(document.getElementById("checkboxID").checked)
    { alert(
    "它处于选中状态"); }

    //判断是否选中通常是使用prop而不是attr
    if($("IsWeek").prop("checked") == true) _IsWeek = 1;

    选中

    $("input:checkbox[name='SNID_PK']").click();

    取消选中

    $("#day").removeAttr("checked");   

    获取状态为【已选中】的checkbox的数量

    var num = $("input:checkbox[name='checkbox']:checked").size();

    Select

    匹配所有选中的option元素

    $("select option:selected")

    选择事件 change 事件

    $('select').change(function (e) {
        var _attr_id = $(this).find("option:selected").attr('attr-id');
         console.log(_attr_id);
    })

    根据text值设置为选中

     $(".selector").find("option[text='pxx']").prop("selected",true);

     $(".selector").find("option:contains('pxx')").prop("selected",true);

    //  $(e).find("option[value="+ value +"]")

    获取当前选中项的value

     $(".selector").val();

    获取当前选中项的text

    $(".selector").find("option:selected").text();

    纯js方式获取text

    var index = document.getElementById('select').selectedIndex;
    var text = document.getElementById('select').options[index].text;
    console.log(20180726092552, index, text)

    清空下拉列表

    $("select#select1").empty();

    Textarea换行符替换

     var str = $("#Cy-Tp-ShopCode").val();
     str = str.replace(/
    /g, ",");  //用g开启贪婪模式匹配替换所有
  • 相关阅读:
    存储过程编译出现锁死情况的解决方法
    国庆带你回家
    端午假期·广州之旅
    造成开发效率底下并且代码难以维护的 35 个恶习
    Linux下mysql自动备份脚本
    在咸阳机场等候登机有感
    vant3图片二进制上传
    浅谈前端缓存(转至大佬)
    vue3中使用$nextTick
    调取接口分页
  • 原文地址:https://www.cnblogs.com/CyLee/p/5324648.html
Copyright © 2020-2023  润新知