• 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 }
  • 相关阅读:
    memcached源码剖析5:并发模型
    memcached源码剖析4:并发模型
    深入剖析php执行原理(4):函数的调用
    深入剖析php执行原理(2):函数的编译
    剖析php脚本的超时机制
    strerror的坑
    深入理解php中的ini配置(2)
    深入理解php中的ini配置(1)
    一个“日期”字符串进行比较的case
    用valgrind检测php扩展内存泄露
  • 原文地址:https://www.cnblogs.com/ashidamana/p/5039181.html
Copyright © 2020-2023  润新知