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>
    

      

  • 相关阅读:
    i++ 与++i
    jquery下的domcument
    jquery
    MVC MVP MVVM
    两个for还是一个for?
    华为云服务器FTP连接
    vue-i18n 使用方法
    在本地运行vue build 文件
    vue项目中使用模拟数据 MOCK
    超简单 超详细 vue项目中使用svg图标 阿里巴巴图标库
  • 原文地址:https://www.cnblogs.com/shenq/p/4924681.html
Copyright © 2011-2022 走看看