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>
    

      

  • 相关阅读:
    Markdown标签
    macbook使用
    git的使用
    HTTPS的原理
    javascript中的对象
    javascript中this的指向问题
    javascript中的闭包
    javaScript中的return、break和continue
    Promise对象
    ORACLE_11G归档空间满,由于数据库装完后使用的是默认空间是闪回区
  • 原文地址:https://www.cnblogs.com/shenq/p/4924681.html
Copyright © 2011-2022 走看看