• 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 }
  • 相关阅读:
    ios启动画面
    不让精灵移除屏幕外 重写setPosition方法
    post和get请求方式的区别
    IOS开发之手势——UIGestureRecognizer 共存
    Xcode 中的GDB的命令
    [UIView beginAnimations:context:]与[UIView animateWithDuration:animations:]值得注意的一个区别
    应用图标 ICON
    cocos2d 1.01不能运行以前版本工程的问题
    SQL 中数据类型的转换 转
    SQL Server中sql语句执行时间
  • 原文地址:https://www.cnblogs.com/ashidamana/p/5039181.html
Copyright © 2020-2023  润新知