<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. SQL Server自动化运维系列——关于邮件通知那点事(.Net开发人员的福利)
  2. comboBox 手动输入后回车自动更新数据
  3. 网络流 poj 3308 最小割
  4. Lua 之os库
  5. mysql 存储过程中limit
  6. JAVA小记
  7. CSS3 :nth-child() 选择器
  8. VS2008 动态库和静态库的生成和加载
  9. Filter及FilterChain的使用具体解释
  10. d指针在Qt上的应用及实现(d指针能实现二进制兼容)
  11. IOS开发:UIAlertView使用
  12. [Swift]LeetCode164. 最大间距 | Maximum Gap
  13. MySQL 分页数据错乱重复
  14. fcn+caffe+制作自己的数据集
  15. The Little Prince-12/11
  16. JAVA⑤
  17. js原型、原型链、作用链、闭包全解
  18. C++&amp;C#外挂(内存修改)
  19. Oracle 给字符串补空格、补0
  20. C语言--指针详解

热门文章

  1. MySQL的安装和启动
  2. 将vim的UltiSnips的快捷键彻底从tab键中分离
  3. 一个有趣的 ”Validation of viewstate MAC failed” 错误的发现和解决
  4. linux调试环境时常用的命令 及 常识
  5. strcmp 与 _tcscmp
  6. java数据类型和码表、转义字符
  7. EF入门
  8. Unittest加载执行用例的方法总结
  9. Redis防护建议
  10. chrome本地测试cookie时无效的原因