代码改变世界

随笔分类 -  web---JavaScript

javascript语言精粹:函数

2012-08-25 16:23 by youxin, 304 阅读, 收藏,
摘要: Functions in JavaScript are objects. Objects are collections of name/value pairs havinga hidden link to a prototype object. Objects produced from object literals arelinked to Object.prototype. Function objects are linked to Function.prototype(which is itself linked to Object.prototype). Every functi 阅读全文

Javascript DOM 编程艺术:Creating Markup on the Fly

2012-08-25 00:57 by youxin, 424 阅读, 收藏,
摘要: 考虑下面的代码:<div id="testdiv"> 空白也是节点<p>This is <em>my</em> content.</p></div>This is how the Document Object Model sees the markup inside “testdiv”, as shown inFigure 7-1:Dom是这么看的:笔记:其实这幅图有错误,一个元素的属性节点不是此元素的子节点。 看下面的代码:var test=document.getElementById(" 阅读全文

Javascript DOM 编程艺术:优雅降级

2012-08-23 23:58 by youxin, 549 阅读, 收藏,
摘要: 这一章可谓本书的核心章节之一。作者不仅介绍了很多实用的技术,更阐明了在 Scripting 编程方面的一些核心理念。学东西,一方面是表面上的规定和技巧,另一方面就是技巧背后的思想了。掌握了这些核心思想,我想在其他领域也可以得到验证和应用。一、过去的错误 作者首先提到了在过去几年里,人们对 JS 的误用造成的不必要的误解。很多网页设计师不愿意去学习 JS,而是仅仅把一些现成的代码片段拿来用,以实现某个特定的功能。他们并没有考虑假如 JS 被禁用,他们的网站还能够正常展现吗?你可能会有疑问,难道还有人手动禁用浏览器的 JS 功能?呵呵,这种人或许很少,但是有一种生物——网络爬虫,它们是不能识别 . 阅读全文

Javascript DOM 编程艺术: popUp

2012-08-23 23:45 by youxin, 399 阅读, 收藏,
摘要: JavaScript uses the open() method of the window object to create new browser windows.The method takes three arguments: window.open(url,name,features)All of the arguments are optional. The first argument is the URL for the document you want to open in a new window. If this is missing, an empty brows. 阅读全文

Javascript DOM 编程艺术:创建一个简单的gallery

2012-08-23 23:20 by youxin, 323 阅读, 收藏,
摘要: 开始的html如下:<!DOCTYPE html><html lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Image Gallery</title></head><body> <h1>Snapshots</h1> <ul> <li> <a hre 阅读全文

Javascript DOM 编程艺术:dom 节点及操作节点方法

2012-08-23 22:25 by youxin, 273 阅读, 收藏,
摘要: element nodestext nodesattribute nodesThere are quite a few other types of nodes. Comments are a separate node type, forinstance. But I’d just like to mention one more node type here.Attributes are used to give more specific information about an element. The title attribute,for example, can be used 阅读全文

Javascript DOM 编程艺术:object

2012-08-23 21:39 by youxin, 318 阅读, 收藏,
摘要: There is one very important data type that we haven’t looked at yet: objects. An object is aself-contained collection of data. This data comes in two forms: properties and methodsA property is a variable belonging to an object.A method is a function that the object can invoke.These properties and me 阅读全文

Javascript DOM 编程艺术:Array

2012-08-23 21:28 by youxin, 327 阅读, 收藏,
摘要: 声明一个定长的数组var beatles = Array(4);Sometimes you won’t know in advance how many elements an array is eventually going tohold. That’s OK. Specifying the number of elements is optional. You can just declare anarray with an unspecified number of elements:var beatles = Array();Adding elements to an array i 阅读全文

转:JS定义类的几种方法

2012-08-23 19:11 by youxin, 258 阅读, 收藏,
摘要: 将近20年前,Javascript诞生的时候,只是一种简单的网页脚本语言。如果你忘了填写用户名,它就跳出一个警告。如今,它变得几乎无所不能,从前端到后端,有着各种匪夷所思的用途。程序员用它完成越来越庞大的项目。Javascript代码的复杂度也直线上升。单个网页包含10000行Javascript代码,早就司空见惯。2010年,一个工程师透露,Gmail的代码长度是443000行!写和维护如此复杂的代码,必须使用模块化策略。目前,业界的主流做法是采用”面向对象编程”。因此,Javascript如何实现面向对象编程,就成了一个热门课题。麻烦的是,Javascipt语法不支持”类”(class), 阅读全文

瀑布流布局

2012-08-18 14:49 by youxin, 516 阅读, 收藏,
摘要: 如果你经常网上冲浪,这样参差不齐的多栏布局,是不是很眼熟啊?类似的布局,似乎一夜之间出现在国内外大大小小的网站上,比如Pinterest(貌似是最早使用这种布局的网站了),Mark之,蘑菇街,点点网,以及淘宝最新上线的“哇哦” 等等,倒是很流行哈~ 在淘宝即将上线的众多产品中,你还会大量看到这样的形式呢。这种布局适合于小数据块,每个数据块内容相近且没有侧重。通常,随着页面滚动条向下滚动,这种布局还会不断加载数据块并附加至当前尾部。所以,我们给这样的布局起了一个形象的名字 —瀑布流式布局。dynamic grid layouthttp://www.fengxiaoqiang.com/blog/2 阅读全文

Js 下拉框新建窗口

2012-08-10 01:08 by youxin, 331 阅读, 收藏,
摘要: <body><form id="aform"><select id="mymenu" size="1"><option value="nothing" selected="selected">Select a site</option><option value="http://www.dynamicdrive.com">Dynamic Drive</option><option val 阅读全文

iframe 使用

2012-08-09 19:50 by youxin, 437 阅读, 收藏,
摘要: <iframe src="http://www.youdao.com" width="500" height="600" ></iframe>属性:frameborder 1 0指定是否有无边框scrolling: auto|yes|no specifies whether or not to display scrollbars in an <iframe>.Use iframe as a Target for a LinkAn iframe can be used as the target f 阅读全文

Js Window Object

2012-08-09 19:39 by youxin, 256 阅读, 收藏,
摘要: The window object represents an open window in a browser.If a document contain frames (<frame> or <iframe> tags), the browser creates one window object for the HTML document, and one additional window object for each frame.alert("An error occurred!")However, the window object i 阅读全文

Js 作用域

2012-08-09 19:15 by youxin, 257 阅读, 收藏,
摘要: Scope is a tricky feature of JavaScript.(棘手的问题) All object-oriented programming languages have someform of scope; it just depends on what context a scope is kept within. In JavaScript, scope iskept within functions, but not within blocks (such as while, if, and for statements). The endresult could b 阅读全文

javascript 冒号使用说明

2012-08-09 18:05 by youxin, 1703 阅读, 收藏,
摘要: JavaScript中冒号(:)是做什么的?你可能经常看到这的写法:<div onclick="javascript:alert('test')">test</div>你可能很习惯认为这是一个伪协议,意思是使用JavaScript语法解析后面的代码,在a标签的href中才是伪协议!那么如果这个代码变成这样呢:<div onclick="xxoo:alert('test')">test</div>你可以试试,代码并不会出错,因为在JavaScript中这样的写法是合法的。其语法 阅读全文

JavaScript 函数重载和类型检查

2012-08-09 17:54 by youxin, 296 阅读, 收藏,
摘要: var variable_name;You can’t use a hyphen, though; it is interpreted as a minus sign. js中变量不能用连字符, 其他面向对象语言如java的一个常见特性是,能够根据传入的不同数量或类型的参数,通过“重载”overload函数来发挥不同的功用。尽管这个特性在js中没有被直接支持,也有很多办法能够实现。 函数重载必须依赖2件事情:判断传入参数数量的能力和判断传入参数类型的能力。我们先来看看参数的数量。 js的每个函数都带有一个包含所有传给函数的参数的伪数组(pseudo array)所有他并非真正意义的数组(也.. 阅读全文

window.onload使用

2012-08-09 16:49 by youxin, 236 阅读, 收藏,
摘要: <html><head> <title>Introduction to the DOM</title> <script> // We can't manipulate the DOM until the document // is fully loaded window.onload = function(){ // Find all the <li> elements in the document var li = document.getElementsByTagName('li'); // 阅读全文

window.onload=function(){}用法

2012-08-09 16:39 by youxin, 1686 阅读, 收藏,
摘要: window.onload=function(){}这是匿名函数的写法,就相当于window的onload事件调用了一个方法,但是这个方法是匿名的常规写法:function Alert(){alert("Hello World!");}window.onload=Alert();匿名写法:</script><script type="text/javascript">function function1(){ alert("1")}function function2(){ alert("2" 阅读全文

$(document).ready()与window.onload的区别

2012-08-09 16:37 by youxin, 222 阅读, 收藏,
摘要: 两者最大的区别,$(document).ready()是在DOM结构载入完后执行的,而window.onload使得在所有文件都加载完后执行的,浏览器执行window.onload函数不仅仅是在构建完DOM树之后, 也是在所有图像和其他外部资源完整的加载并且在浏览器窗口显示完毕之后. 所以如果某个图片或者其他资源加载很长时间, 访问者就会看到一个不完整的页面, 甚至在图片加载之前就执行了需要依赖动态添加的元素的脚本而导致脚本错误.eg:window.onload 用法window.onload = function() { testDiv.innerHTML = "<div s 阅读全文

js prototype及js方法分类

2012-08-09 16:20 by youxin, 330 阅读, 收藏,
摘要: The prototype property allows you to add properties and methods to an object. object.prototype.name=valueavascript中对象的原型属性的解释是:返回对象类型原型的引用。这是一个晕人的解释。其实就是指定了一个需要复制的对象。 文字再多也不如代码,上代码,说最简单的,任何类都继承自Object类:function A(){ }A.prototype=new Object(); 其实这样就相当于Object对象是A的一个原型,这样就相当于了把Object对象的属性和方法复制到了... 阅读全文
上一页 1 ··· 5 6 7 8 9 10 下一页