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>
    
  • 相关阅读:
    Java:多线程
    javascript:正则表达式、一个表单验证的例子
    DOM对象和window对象
    javascript:面向对象和常见内置对象及操作
    如何检查CentOS服务器受到DDOS攻击
    CentOS防SYN攻击
    CentOS服务器简单判断CC攻击的命令
    在VMware中为CentOS配置静态ip并可访问网络
    安全运维之:网络实时流量监测工具iftop
    安全运维之:网络实时流量监测工具iftop
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4603035.html
Copyright © 2011-2022 走看看