jQuery 中的 attr( properties )方法函

首页 / jQuery入门教程 / jQuery 中的 attr( properties )方法函

attr(properties)方法将键/值对象设置为所有匹配元素的属性。

attr(properties) - 语法

selector.attr({property1:value1, property2:value2})

这是此方法使用的所有参数的描述-

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/attr-properties.html

来源:LearnFk无涯教程网

  • property  -  这是匹配元素的CSS属性。

  • value       -  这是要设置的属性的值。

attr(properties) - 示例

<html>
   <head>
      <title>The Selecter Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
   
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
            $("img").attr({ 
               src: "/images/jquery.jpg",
               title: "jQuery",
               alt: "jQuery Logo"
            });
         });
      </script>	
   </head>
	
   <body>
      <div class="division" id="divid">
         <p>Following is the logo of jQuery</p>
         <img src="/jquery/images/jquery-mini-logo.jpg" title="None" alt="None" />
      </div>
   </body>
</html>

这将产生以下输出-

jQuery Logo

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入浅出gRPC -〔李林锋〕

TensorFlow快速入门与实战 -〔彭靖田〕

面试现场 -〔白海飞〕

架构实战案例解析 -〔王庆友〕

视觉笔记入门课 -〔高伟〕

朱涛 · Kotlin编程第一课 -〔朱涛〕

JavaScript进阶实战课 -〔石川〕

大型Android系统重构实战 -〔黄俊彬〕

B端产品经理入门课 -〔董小圣〕

好记忆不如烂笔头。留下您的足迹吧 :)