jquery in action 学习笔记
1
面对对象的编程
1.引用传递
在javascript中,string int Boolean 不是按引用进行传递的.而对象和数组是按引用传递的.
示例:
// Create an array of itemsvar items = new Array("one", "two", "three");// Create a reference to the array of itemsvar itemsRef = items;// Add an item to the original arrayitems.push("four");// The length of each array should be the same,// since they both point to the same array objectalert(items.length == itemsRef.length);
结果是 true
2.每一个Function中都有一个上下文变量arguments,它是一个伪数组(不可以改变).它代表着当前Function的参数列表.
在javascript中,变量的作用域是整个Function,而不是{}.这点有别于c#等其他语言.
// Set a global variable, foo, equal to testvar foo = "test";// Within an if blockif (true) {// Set foo equal to 'new test'// NOTE: This is still within the global scope!var foo = "new test";}// As we can see here, as foo is now equal to 'new test'alert(foo == "new test");// Create a function that will modify the variable foofunction test() {var foo = "old test";}// However, when called, 'foo' remains within the scope// of the functiontest();// Which is confirmed, as foo is still equal to 'new test'alert(foo == "new test");
// A globally-scoped variable, containing the string 'test'
var test = "test";
// You'll notice that our 'global' variable and the test
// property of the the window object are identical
alert( window.test == test );
全局变量可以理解为window的属性.
编写javascript代码时的一些注意事项:
- 要对使用的变量进行声明.以避免不同的作用域时的冲突.
- 理解0 false ‘’ undefined null 这些值在javascript里是相同的,都等于false.
// Both of these are true
null == false
0 == undefined
// You should use !== or === instead
null !== false
false === false
DOM 编程
<p><strong>Hello</strong> how are you doing?</p>
使用DOM的时候,小心一些空白(text)造成的影响,经常使你能找到自己想要的目标元素. function cleanWhitespace( element ) {
// If no element is provided, do the whole HTML document
element = element || document;
// Use the first child as a starting point
var cur = element.firstChild;
// Go until there are no more child nodes
while ( cur != null ) {
// If the node is a text node, and it contains nothing but whitespace
if ( cur.nodeType == 3 && ! /\S/.test(cur.nodeValue) ) {
// Remove the text node
element.removeChild( cur );
// Otherwise, if it's an element
} else if ( cur.nodeType == 1 ) {
// Recurse down through the document
cleanWhitespace( cur );
}
cur = cur.nextSibling; // Move through the child nodes
}
}
使用nodeType属性.
Element (nodeType = 1):如li a input select等元素.
Text (nodeType = 3): 匹配文本元素
Document (nodeType = 9): This matches the root element of a document.
获取元素内的文本内容
需要注意的是innertext在非mozilla浏览器中可以使用,火狐中无法使用.
Listing 5-15. Getting the Text Contents of the <strong> Element
// Non-Mozilla Browsers:
strongElem.innerText
// All platforms:
strongElem.firstChild.nodeValue
获取元素内的html
• Mozilla-based browsers don’t return the <style> elements in an innerHTML statement.
• Internet Explorer returns its elements in all caps, which if you’re looking for consistency
can be frustrating.
• The innerHTML property is only consistently available as a property on elements of HTML DOM documents; trying to use it on XML DOM documents will result in retrieving null values.
获取或设置一个元素的属性值 getAttribute SetAttribute.
Jquery代码学习
Jquery in action 选择器部分学习
Ul li a 不管多少层次,会选中所有符合ul li 下的a.不管多少层级.
Ul li>a 只选择直接孩子的a标签.
Li:has(a)容器选择器,选择包含链接的li元素以进行某项操作.
通过位置进行定位的选择器.
Jquery自定义的筛选选择器:
//防止重复提交的一个方法 w3c官方推荐的属性设置
$("form").submit(function () {$(":submit").attr("disabled", "disabled");});
转载于:https://www.cnblogs.com/huaxiaoyao/archive/2011/02/16/1956526.html
jquery in action 学习笔记相关推荐
- jquery UI 跟随学习笔记——拖拽(Draggable)
jquery UI 跟随学习笔记--拖拽(Draggable) 引言 这周暂时没有任务下达,所以老大给我的任务就是熟悉jquery相关插件,我就先选择了jquery UI 插件,以及jquery库学习 ...
- jquery源码学习笔记三:jQuery工厂剖析
jquery源码学习笔记二:jQuery工厂 jquery源码学习笔记一:总体结构 上两篇说过,query的核心是一个jQuery工厂.其代码如下 function( window, noGlobal ...
- wxPython in Action 学习笔记一
wxPython 学习笔记 第一章 欢迎使用 wxPython 1. 通常情况下,Python 中的模块导入顺序是随意的,相互无关的. 但是 wxPython 中不同,你从 wxPython 导入其他 ...
- [jQuery]黑马课程学习笔记(一篇完)
一.基础 jQuery 是一个 JavaScript 库.是客户端脚本库 jQuery 兼容于所有主流浏览器, 包括 Internet Explorer 6! JavaScript 是 HTML5 以 ...
- jquery备忘学习笔记
$.map(array,fn); 对数组array中的每一个元素调用fn函数逐个进行处理,fn函数将处理返回,最后得到一个新的数组. var array = {1,2,3}; var array2 = ...
- ASP.NET MVC4 IN ACTION学习笔记-第二波
ASPNET MVC4 视图基础(Views fundamentals) --忽然发现我的时间不够了,但是我还是完成了 原著:ASP.NET MVC 4 IN ACTION 本人能力有限,尽量将书中的 ...
- 决策树(chap3)Machine Learning In Action学习笔记
优点:计算复杂度不高,输出结果易于理解,对中间值的缺失不敏感,可以处理不相关特征数据. 缺点:可能会产生过度匹配问题. 适用数据类型:数值型(必须离散化)和标称型. 决策树创建分支的伪代码函数crea ...
- jquery源码学习笔记一:总体结构
练武不练功,到老一场空.计算机也一样. 计算机的功,就是原理.如果程序员只会使用各种函数,各种框架,而不知其原理,顶多熟练工人而已.知其然,更要知其所以然. jquery我们用得很爽,但它究竟咋实现的 ...
- JQuery IN ACTION读书笔记之一: JQuery选择器
本章关注两个通过$()使用的常用功能: 通过选择器选择DOM元素,创建新DOM元素. 2.1 选择操作元素 JQuery采用了CSS的语法,而CSS的语法你可能已经很熟悉了.当然,JQuery也做了扩 ...
最新文章
- 【机器学习】24个终极项目提升您的机器学习知识和技能
- 几个常见规则引擎的简单介绍和演示
- #22. 【UR #1】外星人
- 点云赋值 PointCloudT::Ptr 运行时崩溃
- 神经网络反向传导算法
- Android配置----DDMS 连接真机(己ROOT),用file explore看不到data/data文件夹的解决办法...
- [Java] 蓝桥杯PREV-8 历届试题 买不到的数目
- between and 查询会用到索引吗_这次是真拯救了我,MySQL索引优化,explain讲得非常清楚了...
- ibm watson_使用IBM Watson Assistant构建AI私人教练-第1部分
- eog - eog:19220): GLib-GIO-ERROR **: Settings schema ‘org.gnome.eog.plugins‘ is not installed
- Integer[] cannot be converted to int[]
- Unable to load DLL 'xxx.dll': 找不到指定的模块。 (Exception from HRESULT: 0x8007007E)
- 单片机软件延时的时间计算
- PTA:7-102 喊山 (30分)---解析(bfs广度优先搜索,vector)
- xTiNt 论坛发帖辅助软件 1.0 绿色版
- 原假设“截距为0”双侧检验P值是多少_假设检验——这一篇文章就够了
- 虚拟局域网vlan理论
- 蓝桥杯——2018第九届C/C++真题[省赛][B组]
- 高仿苹果7 plus 3592H
- 全球半导体业瞬息万变 先进制程加快中国已崛起