zoukankan      html  css  js  c++  java
  • jquery知识 属性 css

    jquery基础知识 属性 css

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>属性 css</title>
    <script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
        $(function(){
            //属性
            $('img').attr({'src':'../img2/1.jpg'});//为img标签添加并设置src值
            $('img').attr('alt');//返回img中的src值
            $('img').attr("title",function(){
                return this.src;//将src设置为title的值
            })
            $('img').removeAttr('title')//从img中删除一个属性
            $('img').addClass('cur');//为img添加类名cur
            $('img').removeClass('cur')//为img删除类名cur
            $('img').toggleClass('cur')//如果存在,删除,如果不存在,添加
            $('p').html();//返回p中的内容
            $('p').html('<h1>今天天阴了</h1>');//设置内容
            $('p').text();//取得所有p元素的文本内容,也可设置文本内容
            $('input').val();//获得文本框中的内容
    
            //css
            $('img').css('border','2px');//设置img的css内容
            var offset=$('p:last').offset();//获取偏移对象,存在left和top两个值
            $('p:last').html('left:'+offset.left+',top:'+offset.top);//将两个值让p标签显示
            var position=$('p:first').position();//获取position对象
            $('p:last').html('left:'+position.left+',top:'+position.top)//赋值
            $('p:first').scrollTop();//获取匹配元素相对滚动条顶部的偏移,有参数表示设置
            $('p:first').scrollLeft();//获取匹配元素相对滚动条左侧的偏移,有参数表示设置
            $('p:last').height();//获得匹配元素的高度,有参数表示设置
            $('p:last').width();//获得匹配元素的宽度,有参数表示设置
            $('p:last').innerHeight();//获取第一个匹配元素内部区域的高度
            $('p:last').innerWidth();//获取第一个匹配元素内部区域的宽度
            $('p:last').outerHeight();//获取第一个匹配元素外部区域的高度
            $('p:last').outerWidth();//获取第一个匹配元素外部区域的宽度
        })
    </script>
    </head>
    <body>
        <img alt="风景图" />
        <p>今天天气不错!</p>
        <p>今天心情不错</p>
    </body>
    </html>
    
  • 相关阅读:
    vba合并报表(搬一下)
    自选股票并绘制图像
    python代码--利用python进行数据分析里第十四章缺失代码
    python时间戳(1)
    python学习--列替换问题
    python学习--练习题28
    报错记录--004--panda删除添加问题
    python学习--练习题21-27
    python学习--练习题14-20
    python学习--练习题111213--分阶段判断问题、输出指定日期格式问题、统计字符问题
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4603035.html
Copyright © 2011-2022 走看看