$().attr()的使用方法 && $().html()与$().text()的差别
<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
随机推荐
- Leetcode03---Longest Substring Without Repeating Characters
Description: Given a string, find the length of the longest substring without repeating characters. ...
- Sql Server 如何解决多并发情况下,出现的多个相同ID数据
在数据库中单独创建一张表,保存当前存储状态,“存储过程” 设置访问条件root初始值为“0” 如果root值不为0的时候就不可访问并进行相关操作. 在事务执行前将root值设置为1,事务结束后将ro ...
- iis设置404错误页,返回500状态码
一般在II6下,设置自定义404错误页时,只需要在错误页中选择自定义的页面,做自己的404页面即可.但是在IIS7.0及以上时,设置完404错误页后,会发现状态码返回的是500,并且可能会引起页面乱码 ...
- 移动web——bootstrap响应式工具
基本介绍 1.利用媒体查询功能并使用这些工具类可以方便的针对不同设备展示或隐藏页面内容. 基本使用 <!DOCTYPE html> <html lang="zh-CN&qu ...
- Ajax——jq中ajax的使用
格式化表单 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- inflate(int resource, ViewGroup root, boolean attachToRoot)见解
/** * Inflate a new view hierarchy from the specified xml resource. Throws * {@link InflateException ...
- day12-闭包函数、装饰器
目录 闭包函数 装饰器 无参装饰器 有参装饰器 装饰器模板 闭包函数 之前我们都是通过参数将外部的值传给函数,而闭包打破了层级关系,把局部变量拿到全局使用,并把外部的变量封装到内部函数中,然后下次直接 ...
- 批量obj格式直接转gltf
在cesium中的模型需要的是gltf或glb格式的文件,之前的做法是用将模型从3d max中导出dae格式的文件(需要插件),然后用collada2gltf工具将dae格式转成gltf. 最近翻看c ...
- 【转】jmeter定时调度,持续并发,使用简介
一.安装Jmeter 1.下载Jmeter 下载地址:http://jmeter.apache.org/download_jmeter.cgi 目前最新版为2.9,其余文件如源代码等也可从如下官网下载 ...
- Oracle query that count connections by minute with start and end times provided
数据结构类似 SQL> select * from t; B E N ----------------- ------------ ...