<1>$().attr()的使用方法

</pre><pre class="html" name="code"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="script/jquery-1.11.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//attr用来设置Jquery没有封装的对象属性
//----------------------------------------------------------------------------- $("#btnSubmit").attr("disabled", "true"); //attr用来设置Jquery没有封装的对象属性,由于Jquery没有封装disabled属性,这就是通过attr来将获取到的对象的disabled属性设为true。 //----------------------------------------------------------------------------- //将input的class属性名字设为"inputClass"
$("input").attr("class", "inputClass"); //----------------------------------------------------------------------------- //这里将img的两个属性一并设置了值。就能够用到json格式:{"属性1":值,"属性2":值}
$("img").attr({ "src": "/images/123.jpg", "alt": "123456" }); // $("img").attr({ "src": "/images/123.jpg", "alt": "美女图片" }); 也能够写成以下的形式
$("img").attr("src", "/images/123.jpg").attr("alt", "美女图片"); //----------------------------------------------------------------------------- //将a标签的href属性设为"http://www.baidu.com",将它的html()内容设为"百度"
$("a").attr("href", "http://www.baidu.com").html("百度");
}) </script>
</head>
<body>
<input type="button" value="提交" id="btnSubmit" />
<img/>
<a></a>
</body>
</html>

<2>$().thml()与$().text()的差别

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://localhost:41928/Jquery/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript"> $(function () {
//.thml()是在块中加html代码
$("div").html("<a href='http://www.baidu.com'>百度</a>");
alert($("div").text()); //输出是是一个百度的超链接
}) $(function () {
//.text()是在块中的文字
$("div").text("<a href='http://www.baidu.com'>百度</a>");
alert($("div").text()); //输出的是 【<a href='http://www.baidu.com'>百度</a>】这么一段文字
}) </script>
</head>
<body>
<div></div> </body>
</html>

http://blog.sina.com.cn/s/blog_561be372010008ev.html



随机推荐

  1. cglib动态代理(即AOP)

    Computer.java package com.wh.spring_aop; public class Computer { public void playLOL(){ System.out.p ...

  2. js的toFixed解惑

    js中的toFixed,C#中的Math.round都是按照银行家算法的定义来算的,这里只拿js作参考,各个浏览器的计算方式并不一样,先看一张图,对比参数很容易就发现了其中的不同之处: 前三个Chro ...

  3. SQL SERVER中存储过程IN 参数条件的使用!!!

    正常的传递  @SendStationID='''1'',''2''' 是无效,改用 @SendStationID='1,2,3,003,002' 调用以下的存储过程可以实现in 查询效果 USE [ ...

  4. jQuery——多库共存

    多库共存:jQuery占用了$ 和jQuery这两个变量.当在同一个页面中引用了jQuery这个js库,并且引用的其他库(或者其他版本的jQuery库)中也用到了$或者jQuery这两个变量,那么,要 ...

  5. JS——select标签

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. oracle 用户的操作

    语法: CREATE USER user   IDENTIFIED { BY password              | EXTERNALLY [ AS 'certificate_DN' ]    ...

  7. docker安装后出现Cannot connect to the Docker daemon

    启动docker service docker start docker安装后出现Cannot connect to the Docker daemon You need to add user in ...

  8. Memcached 之PHP实现服务器集群一致性hash算法

    /** * memcached 一致性hash,分布式算法 * Class MemcacheCluster */ class MemcacheCluster { protected $nodes = ...

  9. 【Flutter学习】基本组件之AppBar顶部导航栏

    一,概述 AppBar 显示在app的顶部.AppBar包含5大部分,如下图: 二,构造函数及参数含义 构造函数 AppBar({ Key key, this.leading, //在标题前面显示的一 ...

  10. 基于fpga uart学习笔记

    2018年7月24日 uart 接收 部分测试成功,多谢开源骚客 邓堪文老师 ,想学的同学可以微信公众号搜索开源骚客 好啦!言归正传. 1.先附上老师的时序图,自己有点懒不想画,rx_t.rx_tt. ...