<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. mysql复制数据

    前言:由于工作需要,我要造大量数据,最好的方法是直接copy已有的数据,改其中一些值即可.操作的表有主键,且自增,AUTO_INCREMENT 按照以往的经验无外乎: 类别一. 如果两张张表(导出表和 ...

  2. scala函数用法

    直接上代码. package com.test.scala.test object Function { def main(args: Array[String]): Unit = { println ...

  3. [转]Android杂谈--ListView之BaseAdapter的使用

    本文转自:http://blog.csdn.net/tianshuguang/article/details/7344315 话说开发用了各种Adapter之后感觉用的最舒服的还是BaseAdapte ...

  4. java定时器和实时查询数据库

    定时器: Timer timer = new Timer();                    timer.schedule(new TimerTask() {                  ...

  5. Laravel5.1学习笔记i14 系统架构6 Facade

    Facades 介绍  使用 Facades Facade 类参考   #介绍 Facades provide a "static" interface to classes th ...

  6. html5——背景

    背景大小 background-size: % %;//宽 高 background-size: 100px 100px;//宽 高 background-size: cover;//覆盖,图片会完全 ...

  7. RTL Compiler之Example

    Synthesis = Translation +  Logic Optimization + Mapping Step 1 Source files 1) make directory mkdir ...

  8. %2d

    %2d是C语言中printf函数的输出格式说明符. 具体解释如下: 使输出的int型的数值以2位的固定位宽输出.如果不足2位,则在前面补空格:如果超过2位,则按实际位数输出. 注:如果输出的数值不是i ...

  9. Oracle存储过程及函数的练习题

    --存储过程.函数练习题 --(1)创建一个存储过程,以员工号为参数,输出该员工的工资create or replace procedure p_sxt1(v_empno in emp.empno%t ...

  10. Python爬虫基础--分布式爬取贝壳网房屋信息(Server)

    1. server_code01 2. server_code02 3. server_code03