zoukankan      html  css  js  c++  java
  • jQuery 属性操作

    定义和用法

    attr() 方法设置或返回被选元素的属性值。

    根据该方法不同的参数,其工作方式也有所差异。

    实例1

    设置被选元素的属性和值。

    <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
           $(document).ready(function(){
                 $("button").click(function(){
                     $("img").attr("width","180");
               });
        });
    </script>
    </head>
    <body>
       <img src="/i/eg_smile.gif" />
      <br />
      <button>设置图像的 width 属性</button>
     </body>
    </html>

    实例2

    返回被选元素的属性值。

    <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
           $(document).ready(function(){
                 $("button").click(function(){
                    alert("Image width " + $("img").attr("width"));
                 });
          });
    </script>
    </head>
    <body>
             <img src="/i/eg_smile.gif" width="128" height="128" />
              <br />
               <button>返回图像的宽度</button>
    </body>
    </html>

  • 相关阅读:
    asp.net中ashx文件如何调用session
    NetAdvantage webdatagrid 控件的一些属性
    .NET 配置文件简单使用
    Dictionary的遍历和修改
    利用html+ashx实现aspx的功能
    .ashx
    jQuery AJAX实现调用页面后台方法
    用JS实现AJAX
    WCF系列学习5天速成
    介绍一个小工具 Linqer
  • 原文地址:https://www.cnblogs.com/itdaocaoren/p/4452168.html
Copyright © 2011-2022 走看看