Jquery属性练习
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="http://www.w3school.com.cn/jquery/jquery.js"></script>
<script type="text/javascript">
//设置(增加)name值为none5的input元素的属性id值为none5
//展示id值为none5元素的属性name值
var Init1 = function () {
$("input[name='none5']").attr("id", "none5");
alert($("#none5").attr("name"));
}
//移除id为none6元素的class属性
var Init2 = function () {
$("#none6").removeAttr("class");
}
//prop测试
var Init3 = function () {
//alert($("#none6").prop("class"));//获取属性class值
//$("input[name='none5']").prop("id", "none5");//设置(新增)属性id值为none5
//$("input[name='none5']").prop({ "id": "none5", "value": "none5Value" });//设置属性id为none5,value为none5Value
$("input[name='none5']").prop("value", function () { if (1) return "kktest" });//设置属性value值为function返回的kktest
}
//关于attr与prop的区别参考http://blog.sina.com.cn/s/blog_655388ed01017cnc.html
// 参考http://www.cnblogs.com/lujiahong/articles/2289867.html
//.prop()方法应该被用来处理boolean attributes/properties以及在html(比如:window.location)中不存在的properties。
//其他所有的attributes(在html中你看到的那些)可以而且应该继续使用.attr()方法来进行操作。 //prop及removeProp测试
var Init4 = function () {
//$("input[name='none3']").prop({ "id": "none3", "value": "testValue" });
//$("#none3").removeProp("value");
//以上测试属性均是html中存在的,如果适用removeProp方法,则值变为undefined.应使用removeAttr方法
$("input[name='none3']").prop({ "test": "test1", "test3": "test3" });
alert($("input[name='none3']").prop("test"));
alert($("input[name='none3']").prop("test3"));
$("input[name='none3']").removeProp("test").removeProp("test3");
}
//addClass与removeClass
var Init5 = function () {
$("#none4").addClass("cls1 cls3");
alert($("#none4").attr("class"));
$("#none4").removeClass("cls1");
//$("#none4").removeClass("cls1 cls3");
//$("#none4").removeClass();//只移除属性class的值,要移除属性使用removeAttr
//$("#none4").removeAttr("class");
}
var count = 0;
var Init6 = function () {
$("#none4").toggleClass("cls1");
$("#none4").click(function () {
$(this).toggleClass("highlight", count++ % 3 == 0);
});//根据count++ % 3 == 0值toggle类highlight
} //html()设置或获取html内容
//text()设置或获取内容
//val()设置或获取值 注意arrayArray<String>V1.0用于 check/select 的值
$(Init6);
</script>
</head>
<body>
<input name="none2" />
<form>
<label>Name:</label>
<input name="name" />
<fieldset>
<label>Newsletter:</label>
<input name="newsletter" />
</fieldset>
</form>
<input class="cls1" name="none" />
<input class="cls1" name="none5" />
<input id="none6" class="cls1" name="none6" />
<input name="none3" />
<input id="none4" />
</body>
</html>
Jquery属性练习的更多相关文章
- jQuery属性/CSS使用例子
jQuery属性/CSS 1..attr() 获取匹配的元素集合中的第一个元素的属性的值 或 设置每一个匹配元素的一个或多个属性. 例1:获取元素的属性的值 <p title="段落 ...
- jQuery源代码学习之八——jQuery属性操作模块
一.jQuery属性模块整体介绍 jQuery的属性操作模块分四个部分:html属性操作,dom属性操作,类样式操作,和值操作. html属性操作(setAttribute/getAttribute) ...
- jQuery 属性操作和CSS 操作
如有在jQuery方法中涉及到函数,此函数必定会返回一个数值(函数由于运行次数不同触发一些不同效果) jQuery 属性操作方法(以下方法前些日子学习过,不再赘述) addClass() attr() ...
- jQuery属性操作总结
jquery属性包括以下几个: attr(name|pro|key,val|fn) removeAttr(name) prop(n|p|k,v|f)1.6+ removeProp(name)1.6+ ...
- jQuery 效果函数,jquery文档操作,jQuery属性操作方法,jQuerycss操作函数,jQuery参考手册-事件,jQuery选择器
jQuery 效果函数 方法 描述 animate() 对被选元素应用“自定义”的动画 clearQueue() 对被选元素移除所有排队的函数(仍未运行的) delay() 对被选元素的所有排队函数( ...
- 前端开发之jQuery属性和文档操作
主要内容: 1.jQuery属性操作 2.jQuery文档操作 一.jQuery属性操作 1.什么是jQuery的属性操作? jQuery的属性操作模块包括四个部分:html属性操作,dom属性操作, ...
- jquery 属性选择器
jquery 属性选择器 第一种根据属性选择E[attr] $("[title]").click().......... 即选择所有元素内 属性带有title的元素即<l ...
- jquery——属性操作、特殊效果
1. attr().prop() 取出或者设置某个属性的值 <!DOCTYPE html> <html lang="en"> <head> &l ...
- Jquery属性操作(入门二)
********JQuery属性相关的操作******** 1.属性 属性(如果你的选择器选出了多个对象,那么默认只会返回出第一个属性). attr(属性名|属性值) - 一个参数是获取属性的值,两个 ...
- jQuery属性和样式操作
回顾 1. jquery基本使用 <script src="jquery.min.js"></script><script> $(functio ...
随机推荐
- List中Add()与AddAll()的区别
我们在开发过程中经常会使用到List<Object> list=new ArrrayList<>(); 这个集合,Object 也可以是String.Integer等. 当我们 ...
- 【查找数字x第k为上的数字】
#include<stdio.h> #include<math.h> // 求x用10进制表示时的数位长度 int len(int x){ ) ; )+; } // 取x的第k ...
- JavaSE——线程通信
线程通信: 如果线程A和线程B持有同一个MyObject类的对象object,这两个线程会去调用不同的方法,但是它们是同步执行的,比如:线程B需要等待线程A执行完了methodA()方法之后,它才能执 ...
- PDO添加数据的预处理语句
1.添加页面<h1>添加数据</h1><form action="chuli.php" method="post"> < ...
- JavaScript写计算器
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- cordova app强制横屏
非常简单,只需要在config.xml里加上这行: <preference name="Orientation" value="landscape" /& ...
- python 元组编码和解码问题
先看一个例子: (u'agentEnum', True, '200', {u'msg': u'\u6210\u529f', u'code': 1}) 在2.7.15版本中,如果有下面代码: def f ...
- LeetCode 题解之Reverse Words in a String
1.题目描述 2.问题分析 使用一个vector存储每个单词. 3.代码 void reverseWords(string &s) { vector<string> v; for ...
- DevOps之基础设施-电力
唠叨话 关于噢屁事的知识点,仅提供精华汇总,具体知识点细节,参考教程网址,如需帮助,请留言. <基础设施-电力> 关于基础设施的电力部分,知识与技能的层次(知道.理解.运用),理论与实践的 ...
- mongodb的搭建
1, vi /etc/yum.repos.d/mongodb-org-3.2.repo 2, 添加如下内容 [mongodb-org-3.2] name=MongoDB Repo ...