<!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属性练习的更多相关文章

  1. jQuery属性/CSS使用例子

    jQuery属性/CSS 1..attr() 获取匹配的元素集合中的第一个元素的属性的值  或 设置每一个匹配元素的一个或多个属性. 例1:获取元素的属性的值 <p title="段落 ...

  2. jQuery源代码学习之八——jQuery属性操作模块

    一.jQuery属性模块整体介绍 jQuery的属性操作模块分四个部分:html属性操作,dom属性操作,类样式操作,和值操作. html属性操作(setAttribute/getAttribute) ...

  3. jQuery 属性操作和CSS 操作

    如有在jQuery方法中涉及到函数,此函数必定会返回一个数值(函数由于运行次数不同触发一些不同效果) jQuery 属性操作方法(以下方法前些日子学习过,不再赘述) addClass() attr() ...

  4. jQuery属性操作总结

    jquery属性包括以下几个: attr(name|pro|key,val|fn) removeAttr(name) prop(n|p|k,v|f)1.6+ removeProp(name)1.6+ ...

  5. jQuery 效果函数,jquery文档操作,jQuery属性操作方法,jQuerycss操作函数,jQuery参考手册-事件,jQuery选择器

    jQuery 效果函数 方法 描述 animate() 对被选元素应用“自定义”的动画 clearQueue() 对被选元素移除所有排队的函数(仍未运行的) delay() 对被选元素的所有排队函数( ...

  6. 前端开发之jQuery属性和文档操作

    主要内容: 1.jQuery属性操作 2.jQuery文档操作 一.jQuery属性操作 1.什么是jQuery的属性操作? jQuery的属性操作模块包括四个部分:html属性操作,dom属性操作, ...

  7. jquery 属性选择器

    jquery 属性选择器   第一种根据属性选择E[attr] $("[title]").click().......... 即选择所有元素内 属性带有title的元素即<l ...

  8. jquery——属性操作、特殊效果

    1. attr().prop() 取出或者设置某个属性的值 <!DOCTYPE html> <html lang="en"> <head> &l ...

  9. Jquery属性操作(入门二)

    ********JQuery属性相关的操作******** 1.属性 属性(如果你的选择器选出了多个对象,那么默认只会返回出第一个属性). attr(属性名|属性值) - 一个参数是获取属性的值,两个 ...

  10. jQuery属性和样式操作

    回顾 1. jquery基本使用 <script src="jquery.min.js"></script><script> $(functio ...

随机推荐

  1. python-模板方法模式

    源码地址:https://github.com/weilanhanf/PythonDesignPatterns 说明: 模板方法模式时行为模式中比较简单的设计模式之一.模板方法关注这样的一类行为:该类 ...

  2. cf97D. Robot in Basement(模拟 bitset)

    题意 题目链接 Sol 接下来我的实现方式和论文里不太一样 然后用bitset优化,上下走分别对应着右移/左移m位,左右走对应着右移/左移1位 我们可以直接预处理出能走的格子和不能走的格子,每次走的时 ...

  3. element-ui Steps步骤条组件源码分析整理笔记(九)

    Steps步骤条组件源码: steps.vue <template> <!--设置 simple 可应用简洁风格,该条件下 align-center / description / ...

  4. zigzag方式编码

    按以下公式转换: ParameterInteger = (value << 1) ^ (value >> 31) 参数值不支持大于pow(2,31) - 1或-1 * (pow ...

  5. Oracle 用户、角色管理简介

    Oracle 用户.角色管理简介 by:授客 QQ:1033553122 创建用户 形式1:创建名为testacc2的用户 CREATE USER testacc2 IDENTIFIED BY abc ...

  6. 2018-10-23 23:29:54 clanguage

    2018-10-23   23:29:54 clanguage 在 32 位环境以及 Win64 环境下的运行结果为: short=2, int=4, long=4, char=1 在 64 位 Li ...

  7. html基础笔记-表单、链接

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <!-- 字符编码U ...

  8. centos7 修改中文字符集

    CentOS 7字符集的问题与6有点区别,会出现下面问题,查看是中文,vi进入就变成乱码了 生产中修改配置文件   [root@ce1d2002a999 ~]# cat /etc/locale.con ...

  9. alias 别名

    别名的作用: 1.通过给危险命令加一些保护参数,防止人为误操作. 2.把很多复杂的字符串或命令变成一个简单的字符串或命令. alias 用法: 定义别名: alias rm='echo "没 ...

  10. Java 重写 hashCode() 和 equals() 方法

    1. hashCode 1.1 基本概念 hashCode 是 JDK 根据对象的地址算出来的一个 int 数字(对象的哈希码值),代表了该对象再内存中的存储位置. hashCode() 方法是超级类 ...