jquery in action 学习笔记

1

面对对象的编程

1.引用传递

在javascript中,string int Boolean 不是按引用进行传递的.而对象和数组是按引用传递的.

示例:

 // Create an array of items
var items = new Array("one", "two", "three");
// Create a reference to the array of items
var itemsRef = items;
// Add an item to the original array
items.push("four");
// The length of each array should be the same,
// since they both point to the same array object
alert(items.length == itemsRef.length);
结果是 true
 

2.每一个Function中都有一个上下文变量arguments,它是一个伪数组(不可以改变).它代表着当前Function的参数列表.

 在javascript中,变量的作用域是整个Function,而不是{}.这点有别于c#等其他语言.


// Set a global variable, foo, equal to test
var foo = "test";
// Within an if block
if (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 foo
function test() {
var foo = "old test";
}
// However, when called, 'foo' remains within the scope
// of the function
test();
// 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代码时的一些注意事项:

  1. 要对使用的变量进行声明.以避免不同的作用域时的冲突.
  2. 理解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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/261589.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

matlab实现冲激函数(分数处冲激也行)

clear all; close all; b8; a3; syms X t; tvb/a-3:0.001:b/a3; %定义时间向量 X dirac(a*t-b); Xtsubs(X,t,tv);%调用matlab内置函数 subs(s,old,new),将X中的t替换为tv Xt(find(Xtinf))1; %冲激处幅值置为1 figure(1); plot(tv,Xt);只需更改参数a与b就可以实现任意位置的冲激…

IIS错误与解决方法

转载于:https://www.cnblogs.com/NFFF/archive/2013/06/03/IIS%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%94%99%e8%af%af%e4%b8%8e%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95.html

两种求集合全部子集的方法

如果我们有一个求集合的所有子集(包括集合自身)的需求&#xff0c;即有一个集合s,包括两个元素 <a,b>&#xff0c;则其所有的子集为<a,ab,b>. 不难求得&#xff0c;子集个数sn与原集合元素个数n之间的关系为&#xff1a;sn2^n-1。 本文分别讲述两种实现方法&#x…

ch341a编程和ttl刷机区别_土豪金CH341a编程器 开箱晒物

土豪金CH341a编程器 开箱晒物2019-07-20 11:00:0025点赞119收藏7评论你是AMD Yes党&#xff1f;还是intel和NVIDIA的忠实簇拥呢&#xff1f;最新一届#装机大师赛#开始啦&#xff01;本次装机阵营赛分为3A红组、intel NVIDIA蓝绿组、混搭组还有ITX组&#xff0c;实体or虚拟装机都…

python爬虫爬取百度首页

import requests #导入requests模块 #利用爬虫代码爬去百度首页 #如果当前python文件作为入口程序执行时&#xff0c;则执行if语句下的代码 if __name____main__:# 指定URLurl https://www.baidu.com# 进行UA伪装&#xff0c;模拟浏览器,注意要将相应的User-Agent封装在一个…

最大后验估计_PR Ⅱ:贝叶斯估计/推断及其与MAP的区别

Probabilistic in Robotics Ⅱ: Bayesian Estimation/Inference统计推断旨在根据可观察到的事物来了解不可观察到的事物。即&#xff0c;统计推断是基于一个总体或一些样本中的某些观察变量&#xff08;通常是影响&#xff09;得出结论的过程&#xff0c;例如关于总体或样本中某…

POJ 2187 Beauty Contest

旋转卡壳求最远点对&#xff1b; #include<iostream> #include<cmath> using namespace std; int n,k; double dt; typedef struct point {double x,y;point(double xx0,double yy0):x(xx),y(yy){} }vector; point p[50010],q[50010]; struct line {vector v; }li,…

深入理解并行编程-分割和同步设计(四)

原文链接 作者&#xff1a;paul 译者&#xff1a;谢宝友&#xff0c;鲁阳&#xff0c;陈渝 图1.1&#xff1a;设计模式与锁粒度 图1.1是不同程度同步粒度的图形表示。每一种同步粒度都用一节内容来描述。下面几节主要关注锁&#xff0c;不过其他几种同步方式也有类似的粒…

XHTML标签的嵌套规则

XHTML 的标签有许多&#xff1a;div、ul、li、dl、dt、dd、h1~h6、p、a、addressa、span、 strong……我们在运用这些标签搭建页面结构的时候&#xff0c;是可以将它们无限嵌套的&#xff0c;但是&#xff0c;嵌套也需要有一定规则&#xff0c;不能任由网站设计师的个人习惯胡乱…

python爬虫实现网页采集器

import requests #导入requests模块 #UA&#xff1a;User-Agnet:请求载体身份标识 #UA检测&#xff1a;各大门户网站的服务器都会检测请求载体的身份标识&#xff0c;如果请求载体的身份标识为某一款服务器&#xff0c; #则该请求为正常请求&#xff0c;如果请求载体的身份标识…

mongodb备份oplog_MongoDB 备份(mongodump)与恢复(mongorestore)

MongoDB 备份(mongodump)与恢复(mongorestore)MongoDB数据备份在Mongodb中我们使用mongodump命令来备份MongoDB数据。该命令可以导出所有数据到指定目录中。mongodump命令可以通过参数指定导出的数据量级转存的服务器。语法mongodump命令脚本语法如下&#xff1a;>mongodump…

[转]MVC中如何使用RDLC报表

本文转自&#xff1a;http://www.cnblogs.com/BlueWoods/archive/2009/04/27/1444311.html 在用MVC开发项目的时候遇到了一个问题&#xff0c;如何运用RDLC报表&#xff1f; 首先想到的是在Controller返回DataSet,然后在View绑定值&#xff0c;但是遇到一个异常&#xff1a;...…

关于javascript作用域

今天一个挚友给我出了道javascript笔试题&#xff0c;代码如下&#xff1a; function test(){var a b 2; } test(); alert(b); alert(a);我看到这段代码&#xff0c;我笑了&#xff0c;很自信的回答道&#xff0c;会报错&#xff0c;因为a,b都是局部变量&#xff0c;所以a an…

string类的实现(构造函数,析构函数,运算符重载)

String类的代码&#xff1a;class String { public:String(char* str""){_str new char[strlen(str) 1];strcpy(_str, str);}String(const String& str){_str new char[strlen(str._str) 1];strcpy(_str, str._str);}~String(){delete[] _str;}String& o…

html网页设计一个简单的用户登录页面

结果 代码 login.html <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>用户登录页面</title><link rel"stylesheet" href"./css/login.css"><script src"j…

python url模块介绍_python 中 urlparse 模块介绍

urlparse模块主要是用于解析url中的参数 对url按照一定格式进行 拆分或拼接1.urlparse.urlparse将url分为6个部分&#xff0c;返回一个包含6个字符串项目的元组&#xff1a;协议、位置、路径、参数、查询、片段。import urlparseurl_change urlparse.urlparse(https://i.cnbl…

欢迎光临CAX软件二次开发开源社区!

欢迎光临CAX软件二次开发开源社区&#xff01; http://uucax.uueasy.com转载于:https://www.cnblogs.com/uucax/archive/2011/02/20/1959265.html

ORA-20446: The owner of the job is not registered ORA-06512: at SYSMAN.MGMT

Login as sysman user to the database and execute the following :execute MGMT_USER.MAKE_EM_USER(ARCER);//标红处为需要导出导入权限的用户的用户名 备注:假如你没有开启SYSMAN用户&#xff0c;自行开启&#xff1b;转载于:https://www.cnblogs.com/arcer/archive/2013/06…

ip聚合简介

练习一 本题选择&#xff1a;D 解释如下&#xff1a; 人事部 205.67.159.1110 0000 /27 培训部 205.67.159.1101 0000 /28 销售部 205.67.159.1100 0000 /28 先是培训部与销售部做IP聚合&#xff08;只有网络前缀位数相同才可以做ip聚合&#xff09; 保留相同的位数&…

css编写的技巧效果总结

1. 垂直对齐 如果你之前遇到过这个问题&#xff0c;你就应该知道它是多么的烦人&#xff0c;幸运的是&#xff0c;现在你可以使用CSS3变换来解决这个问题&#xff1a; .vc{ position: relative; top: 50%; -webkit-transform: translateY(-50%); -o-transform: translateY(-50%…