zoukankan      html  css  js  c++  java
  • 设置属性和获取属性

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>设置属性和获取属性</title>
        <script src="js/jquery-1.7.1.js"></script>
        <script>
            $(function(){
                alert($('.box').attr('class'));//获取属性值;为box;
    
                $('.box').attr('title','nihao');//设置属性的属性值;
    
                $('.box').attr({
                   'title':'nihao',
                    'class': 'red',//class不建议用attr来创建,后面有更强大的功能;
                    'data':'123'  //最后一个不用逗号
                });
    
                $('.box').attr('title',function(index,value) {//如果原先没有title,那么返回    //undefind;
                                                            // index是索引,从0开始
                    return '原来的title是' + value +',现在的title是' + '我是' + index + '号';
    
                });
                var arr = ['haha','hahahahaha','yaya'];
    
                $.each(arr, function(index,value) {
                    return $('p').text(value);
                });
                $('p').text(function(index,value) {
                    return arr[index];
                    return value + ' + ' + arr[index % arr.length];
                });
            });
    
        </script>
    </head>
    <body>
    <div class="box1" title="aaa"><p>hello</p></div>
    <div class="box2" title="bbb"><p>world</p></div>
    <div class="box1" title="aaa"><p>yu</p></div>
    <div class="box2" title="bbb"><p>world</p></div>
    
    </body>
    </html>
    

      

  • 相关阅读:
    luogu1210 回文检测
    luogu2420 让我们异或吧
    luogu4151 最大XOR和路径
    线性基
    博弈论(扯淡)
    矩阵求逆 模板
    luogu2513 逆序对数列
    洛谷4316 绿豆蛙的归宿(DAG递推/概率dp)
    1898: [Zjoi2005]Swamp 沼泽鳄鱼
    矩阵
  • 原文地址:https://www.cnblogs.com/shenq/p/4924681.html
Copyright © 2011-2022 走看看