<!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. jquery插件-fullpage.js

    1⃣️ 简介 fullPage.js 是一个基于 jQuery 的插件,它能够很方便.很轻松的制作出全屏网站,主要功能有: 支持鼠标滚动 支持前进后退和键盘控制 多个回调函数 支持手机.平板触摸事件 ...

  2. Tracing 在PeopleSoft 程序中怎么开启

    本文介绍一些常用的跟踪方法在Applications,Application Engine,PeopleSoft,Integration Broker,Cobol中. 1.Application En ...

  3. Nginx的性能优化

    1.优化worker进程个数: 在高并发.高访问量的WEB服务场景,需要事先启动更多的nginx进程,以保证快速响应并处理大量并发用户的请求,优化nginx进程个数的配置项就是,在nginx.conf ...

  4. 《ECMAScript6标准入门》第三版--读书笔记

    2015年6月,ECMAScript 6正式通过,成为国际标准.尽管在目前的工作中还没有使用ES6,但是每项新技术出来总是忍不住想尝尝鲜,想知道ES6能为前端开发带来哪些变化?对自己的工作有哪些方面可 ...

  5. Oracle EBS 物化视图

    怎么理解物化视图呢,先随意拿一个建物化视图的例子看一下. create materialized view EBS_ACCOUNTS_HIERARCHY_MV refresh complete on ...

  6. css继承属性与非继承属性

    一.无继承性的属性 1.display:规定元素应该生成的框的类型 2.文本属性: vertical-align:垂直文本对齐 text-decoration:规定添加到文本的装饰 text-shad ...

  7. CreateProjectFormat——初始项目目录格式

    百度云链接:https://pan.baidu.com/s/1f_2YaMf9619Rt5AlC6nryQ 密码:v2cb 修改中...

  8. ip 命令的使用

    网上相似的资源很多,可以参考如下资料: man ip ip help 博客链接: https://linoxide.com/linux-command/use-ip-command-linux/ ht ...

  9. NFS网络共享介绍与使用

    什么是NFS(网络文件系统)? NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.它的主要功 ...

  10. Practice telephone techniques

    https://www.englishclub.com/speaking/telephone-practice-appointments.htm https://www.englishclub.com ...