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 }
  • 相关阅读:
    idea快捷键总结
    将对象序列化和反序列化
    在Springmvc中获取properties属性
    配置springmvc在其他类中(spring容器外)获取注入bean
    redis学习之三配置文件redis.conf 的含义
    redis学习之二from github
    敏捷开发方法XP的12个最佳实践
    IIS-网站发布之后访问HTTP 错误 403.14
    IIS-将iis直接指向.net代码会出现错误
    HTTP 错误 500.24
  • 原文地址:https://www.cnblogs.com/ashidamana/p/5039181.html
Copyright © 2011-2022 走看看