zoukankan      html  css  js  c++  java
  • jquery取值赋值

    ("#A").val("1") id为A的值就是1了 

    jQuery中都这样,赋值的时候作为参数传给函数,和单纯的js有区别,像

    $("#A").html("1")

    $("#A").text("1") 都是赋值 

    $("#A").html() 

    $("#A").text() 都是取值,取html,取text文本 


    nput[class* =required]

    查找出所有input标签,且class="required"的input


    实例:

    $(document).ready(function(){
        var idsstr = "";
        var isc = "";
        $("#a input[name=chkId]").each(function(){ //遍历table里的全部checkbox
            idsstr += $(this).val() + ","; //获取所有checkbox的值
            if($(this).attr("checked")) //如果被选中
                isc += $(this).val() + ","; //获取被选中的值
        });
        if(idsstr.length > 0) //如果获取到
            idsstr = idsstr.substring(0, idsstr.length - 1); //把最后一个逗号去掉
        if(isc.length > 0) //如果获取到
            isc = isc.substring(0, isc.length - 1); //把最后一个逗号去掉
        alert("所有checkbox的值:" + idsstr);
        alert("被选中checkbox的值:" + isc);
    });

    实例2:

    这个是工作中遇到的,获取多个下拉框的值以集合的方式赋值给input,

    例如:value="3,24,32"

     1 function getContent(){
     2   var idsstr="";
     3   var idselect="";
     4  //取出所有input隐藏域类名为myhd的值
     5  $("input[class*=myhd]").each(function(){
     6  idsstr += $(this).val()+",";
     7 })
     8  //取出所有select标签类名为mySe的值
     9  $("select[class*=mySe]").each(function(){
    10   idselect += $(this).val()+",";  
    11 })
    12 //把值赋给input标签属性name为ProductIds
    13 $("input[name=ProductIds]").val(idsstr);
    14 //同上
    15 $("input[name=CountIds]").val(idselect);        
    16 }
  • 相关阅读:
    构建maven项目,自定义目录结构方法
    Nginx反向代理实现负载均衡以及session共享
    Spring Boot 2.x引入JS,CSS 失效问题
    WebMvcConfigurerAdapter已过时
    闲谈Tomcat性能优化
    oracle decode函数和 sign函数
    为什么要使用MQ和到底什么时候要使用MQ
    redis持久化的几种方式
    【mySQL】left join、right join和join的区别
    redis缓存在项目中的使用
  • 原文地址:https://www.cnblogs.com/ashidamana/p/5039181.html
Copyright © 2011-2022 走看看