归档

记录点滴,修炼自己。
0

PWA-渐进式Web应用探究

定义 Progressive Web Apps are experiences that combine the best of the web and the best of apps.They are useful to users from the very first visit in a browser tab, no install required.As the user prog

0

移动端HTML5响应式布局适配解决方案

前言  移动端适配是一个十分重要的问题。在移动端页面中,其布局和交互方式可能相比于PC端少一些,但是由于设备的多样化,其适配问题就必须多加关注。设备情况种类繁多复杂,从网上的几张图中足以看出: 基本概念物理像素(physical pixel)一个物理像素是显示器(手机屏幕)上最小的物理显示单元,在操作系统的调度下,每一个设备像素都有自己的颜色值和亮度值。 设备独立像素(density-inde

0

使用SwitchyOmega和Charles配置统一的开发和生产环境

本文是客户端代理配置的几种常见方式的一部分内容,主要针对SwitchyOmega和Charles两种工具。 前言  代理服务器是开发过程中的常用工具。通过配置代理,可以统一线上线下环境,在开发阶段也访问线上地址,只不过将请求流量代理到本地服务器,这样便于调试。 Chrome插件SwitchyOmega  该插件可以通过Chrome应用商店进行下载,典型的配置过程如下:1.新建情景模式,选择

0

React开发框架Dva.js项目结构简单小结

前言  本篇简单对Dva.js项目的工程结构进行说明,具体的概念,设计,文档,详见Dva.js官网 项目结构 mock属于前后端分离的一种实践,在后端接口未完全实现时,前端可通过mock数据的方式自测。 node_modules项目依赖采用npm管理,所以来包均在此目录。 srcassets项目静态资源目录(图片等) components无状态组件目录。根据react组件化的要求,该目录下

0

git merge 与 git rebase 的对比分析

相关概念  以下概念和示例参考http://blog.csdn.net/wh_19910525/article/details/7554489 背景假设现在基于远程分支”origin”,创建一个叫”mywork”的分支。$ git checkout -b mywork origin假设远程分支”origin”已经有了2个提交,那么新创建的mywork分支在现在未修改的状态下是和origin具有相

0

JavaScript中比较运算的详细总结

前言  在javascript开发中,比较操作是十分常见的。由于显式/隐式强制类型转换机制的存在,我们在使用比较运算时显得过于随意,也许表面上看并没有什么错误(比如在if()语句中判断两值相等时顺手就写成 == ),但是这可能会埋下很多不易发现的隐患。对于比较操作(相等关系和不等关系),在javascript中其实是有一套完善的机制的。本文依据ES5规范《ECMAScript Language

0

JavaScript中对象属性存在性及相关检测方法总结

前言  访问一个对象中的某个属性时,返回的结果可能是undefined,这有可能是本身该属性存储的值就是undefined,也有可能是该属性在对象中不存在。对此,就产生了判断属性存在性的相关问题和解决方法。 in操作符语法格式1234567var obj = { name : "Bob", age : 24};("name" in obj); //true("sex" i

0

【探究】当页面关闭时,不同浏览器对尚未完成的异步请求如何处理?

前言  以使用$.ajax()方法发出一个异步请求为例,探究当执行完发出异步请求的同步代码但尚未执行异步回调的函数的时候,关闭浏览器,不同浏览器对此有何处理。并且,这个问题是因为看到了一种不规范写法而发现的—场景是,执行完相关保存任务(异步请求)后关闭当前页面。这种写法把window.close()相关代码却写在了$ajax()的外面(后面)。违背了在成功保存的回调内关闭页面的做法。 Chro

0

常见数据格式的正则表达式验证

前言  正则表达式是一种强大的工具,可以在很多场景下对我们需要的内容进行快速匹配过滤。比如,在前端提交表单时,就可以通过编写合理的正则表达式对用户输入进行首次过滤(当然服务端程序在接收到数据后一样要进行严格的数据检查,保证程序正常运行,防止通过postman等工具绕过前端验证进行恶意攻击。) 正则表达式的学习  网上有很多系统学习正则表达式的资源,掌握基本的语法和相关机制是实现常见数据格式验证的

0

前端优化:[dns-prefetch] DNS预解析

背景  对提升网页性能,提高加载速度和用户体验的不断重视。 定义与优势  DNS Prefetch,即DNS预获取,是前端优化的一部分。当你浏览网页时,浏览器会在加载网页时对网页中的域名进行解析缓存,这样在你单击当前网页中的连接时就无需进行 DNS 的解析,减少用户等待时间,提高用户体验。一般来说,在前端优化中与 DNS 有关的有两点: 减少DNS的请求次数 进行DNS预获取 现在大多数

0

React的state初始化及其在dva框架中的具体表现

前言  本篇结合在使用dva框架进行React应用开发过程中遇到的问题,简要分析React中state的机制和Redux对state的状态管理。 使用dva框架开发时遇到的一个问题  关于dva框架的基本结构和开发模式,在之前的文章中已经有所提及,见React开发框架Dva.js项目结构简单小结。下面的描述直接基于框架中的概念。 问题现象描述确定接口所需数据结构  在进行一个应用模块的开发,与

0

JavaScript中的对象、constructor属性、prototype属性对比分析

前言  首先想说的是,这篇文章的题目准确怎么定我就考虑了不少时间。想过“JavaScript中的对象及其constructor属性和prototype属性”,想过“JavaScript中的对象、构造函数对象(constructor)和原型对象(prototype)”等等,但总觉得不够清楚。说实话现有的这个题目也不一定是很好的,只是相比较之下,选择一个“三者相对独立”的说法,这样就不会有先入为主的

0

JavaScript中值传递和引用传递的典例探究

概述  在Javascript中,基本类型(null, undefined, number, string, boolean, symbol)是通过值传递方式进行,而复合类型(object, array, function)则是通过引用传递方式进行。  但是,由于Javascript工作机制所决定,在js中,引用指向的其实是值,而无法指向其他引用,这和其他语言中的指针并不相同。  其实,两者都可

0

JavaScript中创建对象的7种模式和实现继承的6种方式

前言  JavaScript是一种面向对象(OO)的语言,但由于ECMAScript没有类的概念(ES6引入关键字class),所以在js中创建对象的方法也与其他基于类的语言有所不同。本篇总结在JavaScript中创建对象的7种方法;并在此基础上,总结实现继承的6种方式。 JavaScript中对象的基本概念创建对象的2种基本方法 创建一个Object实例123456var person =

0

关于JavaScript生成器generator和yield的一些理解

综述  Generator(生成器)函数是ES6提供的一种异步编程解决方案,而yield则是配合生成器函数使用的。 Generator函数定义  function* 声明(function关键字后跟一个星号)定义一个generator(生成器)函数,返回一个Generator对象。 语法function* name([param[, param[, ... param]]]) { statem

0

Base64编码探究

概念  Base64编码是网络传输中的一种常见编码方式。可用于传输任意的8bit(字节Byte)数据,经过编码后的数据不是直接可读的,但也由此保证了一定的安全性和很好的可移植性。这种编解码的算法十分简单,编码后的数据大小仅增加三分之一左右(原因后续讲到),因而不会对传输造成过大压力。  我们需要明确的概念是,Base64编码本质上是将二进制数据编码为文本字符。而这些二进制数据的来源则可能有很多,

0

使用WebStorm创建webpack工作流的前端项目

前言  webpack是一款极为灵活的前端模块打包构建工具。其诞生和流行主要是由于以下这几个发展趋势: 为了完成更加复杂的交互逻辑,一个网页中使用的js代码数量越来越多; 即便有了更多代码,却要求使用中有更少的整页面重新加载; 现代浏览器提供了更多的API接口。   基于这样的情况,大量代码就需要能够被良好地管理起来,像webpack这样的模块系统就为我们将代码切分为若干模块提供了很好的选择

0

JavaScript中的__proto__、[[prototype]]和prototype

前言  proto、[[prototype]]和prototype三个概念及相关内容是javascript比较复杂且容易混淆的内容。本文尝试进行总结和分析。 prototype相关介绍  待续。 __proto__与[[prototype]]相关介绍  待续。 一张图分析三者的关系 一系列案例分析12345function Foo(){ console.log(1);}

0

CSS居中问题总结

前言  本篇集中对CSS中的各种居中问题进行总结。整体上需要居中的元素可以分为两大类-内联元素和块级元素,而居中方式又要考虑水平和垂直两个方向。 内联元素居中水平居中 使用”text-align:center”根据以下W3C的官方文档: 属性“text-align”用于描述块级元素中的行内内容如何布局。我们知道,块级元素的显示占据一整行,而行内元素可以在一行内并列显示,常用的行内元素有<

0

【阿里云ECS】GitLab的搭建配置过程和GitLab-CI服务的使用

前言  GitHub是一个十分著名并相当活跃的社区,每天有世界各地的程序员在这里分享与交流。作为开源项目或者技术分享,我们当然可以将代码维护在这里。但是对于内部项目,我们应该具备私有仓库来进行维护。GitLab就是一个很好的选择。本文主要包括以下几个方面: Git安装与使用 GitLab相关知识介绍 GitLab搭建配置的完整过程 GitLab-CI相关知识介绍 GitLab-CI安装配置的完

0

【阿里云ECS】LAMP开发环境的完整搭建配置过程

前言  为了顺利进行web开发,一套完整易用的开发环境是十分必要的,这可以大大提高团队的合作和开发效率。这里说的开发环境包括IDE,数据库,开发语言组件,版本控制工具等一系列内容。最近在使用的是比较流行的php开发架构,在windows下,无疑推荐WAMP + MySQL-Front + phpStorm,WAMP集成了Apache、MySQL、PHP,可以免除许多安装配置的问题。这样的环境在具体开发中是没有什么问题的,但是当项目上线并且需要版本维护时,我们还是要在Linux系统上进行部署。  基于这样的需求,最近搭建了一套完整的LAMP环境并测试通过,可以实现代码版本控制,APP端API测试调用,项目自动化部署持续集成(CI)。包括的主要内容有:

0

React Router的history探究

前言  路由是单页应用中十分重要的概念。具体在react中,react-router为我们提供了一套完整的路由机制。 概述  项目history相关文档主页:Histories。文档的讲解十分详细。本文只是通过在实际项目中history的状态变化进行简单小结。以dva应用为例,经过这样的配置后,容器组件可以在props中拿到history对象和相关参数。 表现如上所示,history中包含了一

0

客户端代理配置的几种常见方式

PAC文件  PAC文件是一些简单的javascript程序,可以在运行过程中计算代理设置,是一种动态方案。配置方案示例如下(以登录内部局域网为例):在IE浏览器Internet选项做如下配置,填写的地址是目标服务器上的代理配置文件根据已有信息访问代理进行登录后可以使用。 PAC文件结构如下: Chrome插件SwitchyOmegaCharles Web Debugging Proxy注:以上

0

Bootstrap等前端框架栅格系统的原理

栅格系统基本使用方法基本原理  Bootstrap 提供了一套响应式、移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列。它包含了易于使用的预定义类,还有强大的mixin 用于生成更具语义的布局。  栅格系统用于通过一系列的行(row)与列(column)的组合来创建页面布局,你的内容就可以放入这些创建好的布局中。下面就介绍一下 Bootstrap

0

客户端浏览器检测

前言  几种web浏览器在实现相关标准时会有一些差异和区别,这可能会给开发带来一些问题。此时就会需要进行客户端检测从而给出不同的方案。但是,从根本上来讲,只要能够找到更通用的方法,就应该优先采用更通用的方法,先设计最通用的方案,然后再使用特定于浏览器的技术增强该方案。《JavaScript权威指南》相关描述如下: 检测方法与主要参数navigator对象的主要参数 方法 主流浏览器的userAg

0

JavaScript的预加载与懒加载

预加载目的  增强用户的体验,当用户需要查看时可直接从本地缓存中渲染。。否则,如果一个页面的内容过于庞大,没有使用预加载技术的页面就会长时间的展现为一片空白。但会加载服务器的负担。并且,如果不设置预加载,那么当需要渲染十分大的图片时,可能就会有“逐行扫描渲染”的感觉,用户体验不好。使用预加载的话,我们可以在图片完整渲染完成之前在页面上设置“loading”类的图标提示,而当图片数据完全获取后一次

0

使用AngularJs封装Tabs选项卡组件

angular-table使用AngularJs封装Tabs选项卡组件 功能描述  该组件是管理系统中很常用的功能,平台使用者可能会同时使用不同模块的功能,这时候需要打开多个模块,Tabs组件是一种类似浏览器多标签页的效果。可以: 可以在多个模块的页面间进行切换 在某个页面上右键关闭 附带收起侧边栏功能 … 实现 demo源码托管于github,详见Github gcidea/angula

0

CSS预处理---Less使用案例

前言示例12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152@import "../../assets/less/common";.countDownAd { &:extend(.flexLayout); padding: 30rem /

0

使用AngularJs封装表格内容渲染(含分页)组件

功能描述  该组件是管理系统中很常用的功能,管理系统的典型使用是批量数据的处理,表格展示是最直接的方式。该插件实现: 批量数据的列表展示 每行数据提供操作项(修改,删除等)接口 翻页查询接口 每页显示条数修改 点击表头排序 列表宽度自定义 … 实现 demo源码托管于github,详见Github gcidea/angular-table html结构  承载该表格插件的主要html结

0

AngularJs中使用拦截器interceptor对全局HTTP错误进行统一处理

前言  在web开发的各种业务场景中,http请求无疑是家常便饭,任何前后端交互数据都需要通过http请求进行传输。同时我们知道,HTTP响应有很多状态码,对应着很多种不同的服务处理结果。在这种情况下,如果项目中每一处http请求中我们都要对各种响应结果做以判断的话,那么整个工程中就会出现大量重复代码,这样做会带来不少问题,比如:重复劳动,代码结构不清晰、核心逻辑不明确,一旦对错误处理的需求变更

0

AngularJs的$emit和$broadcast事件分析

前言  Angular的作用域在本质上是分层次的:它们可以通过父子关系很自然地来回沟通。但通常,作用域是不共享变量的,它们执行的功能往往各不相同,跟在父树上的位置无关。在这种情况下,我们可以通过在这个链上传递事件的方式在作用域之间通信。  因为作用域是有层次的,所以我们可以在作用域链上传递事件。通常来说,选择要使用的事件传递方式,一个好的经验法则是:查看将要触发事件的作用域。如果要通知整个事件系

0

AngularJs中组件---component的相关总结

前言  组件component是AngularJs中一个非常重要的概念,一个项目的前端代码结构可以完全以组件component为单位进行实现,也就是说项目的不同页面(比如列表页、详情页、编辑页)或者通用功能(比如表格渲染组件、分页组件)都可以设计为一个独立的component,再通过路由配置关联起来,实现功能需求。本篇以AngularJs官方文档为根据,对组件相关内容进行总结。 综述  在An

0

AngularJs中$scope.$apply()方法总结

功能  $apply()函数可以从Angular框架的外部让表达式在Angular上下文内部执行。例如,假设你实现了一个setTimeout()或者使用第三方库并且想让事件运行在Angular上下文内部时,就必须使用$apply()。 参数  $apply()函数接受一个可选的参数。这个表达式可选地接受一个字符串或函数,并且是在当前作用域内执行。如果传入一个字符串,$apply()首先会在这个

0

AngularJs中$q服务(service)的使用

前言  $q服务的实现与ES6(ES2015)中的promise十分相似,这种方式改变了传统长期使用的JavaScript异步编程方式-处理回调函数。试想一下,如果有这样的业务逻辑:我们需要根据某个异步ajax请求的结果是否符合要求,再发起一个异步请求,在回调函数中对响应数据进行请求后再发起异步请求… …当出现这样的异步嵌套逻辑,代码结构就会变得很差。promise正是改变了这种情况,以一种流式

0

Nginx服务器基本配置及在模块化项目中的转发应用

nginx概述 来源  Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。Nginx是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。2011年6月1日,nginx 1.0.4发布。 特点  占有内存少,并发能力强。Nginx可以在大多数Unix

0

使用dora-proxy-plugin处理异步请求跨域问题

前言  这个问题描述的背景,是基于访问本地前端项目的nodejs服务器,但是却请求线上API数据接口的场景。如果能做到统一本地线上环境是更好的,有利于维护和调试,具体做法可以参考:使用SwitchyOmega和Charles配置统一的开发和生产环境、客户端代理配置的几种常见方式 概述  根据前后端分离的原则,前端独立进行功能的开发,在与后端真实接口进行对接之前,可以自己通过mock数据的方式进行

0

Hexo博客框架配置优化-网站sitemap和RSS源订阅

前言  Sitemap 可方便网站管理员通知搜索引擎他们网站上有哪些可供抓取的网页。最简单的 Sitemap 形式,就是XML 文件,在其中列出网站中的网址以及关于每个网址的其他元数据(上次更新的时间、更改的频率以及相对于网站上其他网址的重要程度为何等),以便搜索引擎可以更加智能地抓取网站。    简易信息聚合(也叫聚合内容)是一种RSS基于XML标准,在互联网上被广泛采用的内容包装和投递协议。

0

智慧交通数据可视化展现Demo

简介demo基于csv等格式的数据处理结果文件,对数据进行可视化展现。 模块划分 目标区域驻留人数统计 高铁到发站人流量统计 地铁到发站人流量统计 行政区客流量分析 城市职住分布 交互方式及效果呈现 demo源码托管于github,详见Github gcidea/data-visualization 下载完整的文件目录,浏览器(推荐Chrome)打开根目录下index.html即可。五个模块

0

HTTP协议的持久连接-"keep-alive"与"persistent"

前言 “keep-alive”概述  HTTP协议采用“请求-应答”模式,当使用普通模式,即非KeepAlive模式时,每个请求/应答客户和服务器都要新建一个连接,完成之后立即断开连接(HTTP协议为无连接的协议);当使用Keep-Alive模式(又称持久连接、连接重用)时,Keep-Alive功能使客户端到服务器端的连接持续有效,当出现对服务器的后继请求时,Keep-Alive功能避免了建立

0

浏览器的文档模式-“标准模式”和“怪异模式”

前言  所谓的标准模式是指,浏览器按W3C标准解析执行代码;怪异模式则是使用浏览器自己的方式解析执行代码,因为不同浏览器解析执行的方式不一样,所以我们称之为怪异模式。浏览器解析时到底使用标准模式还是怪异模式,与你网页中的DTD声明直接相关,DTD声明定义了标准文档的类型(标准模式解析)文档类型,会使浏览器使用相应的方式加载网页并显示,忽略DTD声明,将使网页进入怪异模式(quirks mode)

0

JavaScript中的事件传播机制

前言  javascript与html的交互是通过事件实现的。在DOM2级模型中,为DOM元素绑定的事件有一套完整的事件传播机制,主要有3个阶段,本文进行小结。 ##

0

git pull 与 git fetch 的区别

概述引用网上的一张图来说明 对比git fetch1.git fetch这将更新git remote 中所有的远程repo 所包含分支的最新commit-id, 将其记录到.git/FETCH_HEAD文件中。 2.git fetch remote_repo这将更新名称为remote_repo 的远程repo上的所有branch的最新commit-id,将其记录。 3.git fetch r

0

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

document.ready执行时机  只要页面DOM结构绘制完毕就执行,不必等到外部资源(图片,css等)加载完毕。 并且,在jquery中,$(function(){}) 和$(document).ready(function(){})两种写法是等价的。 特点  在同一个页面中可以写多次,会顺序执行,见下面测试。 window.onload执行时机  必须等到页面内包括图片的所有元素加载完

0

JavaScript异步编程案例

【转载】阮一峰 Javascript异步编程的4种方法 前言你可能知道,Javascript语言的执行环境是”单线程”(single thread)。 所谓”单线程”,就是指一次只能完成一件任务。如果有多个任务,就必须排队,前面一个任务完成,再执行后面一个任务,以此类推。 这种模式的好处是实现起来比较简单,执行环境相对单纯;坏处是只要有一个任务耗时很长,后面的任务都必须排队等着,会拖延整个程序的执

0

前端常用的几种图片格式及使用场景

基本概念矢量图与位图  矢量图是通过组成图形的一些基本元素,如点、线、面,边框,填充色等信息通过计算的方式来显示图形的。一般来说矢量图表示的是几何图形,文件相对较小,并且放大缩小不会失真。  位图又叫像素图或栅格图,它是通过记录图像中每一个点的颜色、深度、透明度等信息来存储和显示图像。一张位图就好比一幅大的拼图,只不过每个拼块都是一个纯色的像素点。位图的优点是利于显示色彩层次丰富的写实图像。缺点

0

可视化HTML5页面拖拽构建工具demo

简介  demo,在web端通过拖拽编排的方式快速定制活动H5页面,初步阶段完成。 交互方式及效果呈现 demo源码托管于github,详见Github gcidea/html5-draggable 使用流程1.拖拽页面布局至手机预览区2.根据不同类型的布局,点击可以编辑不同参数3.布局定制完成后可以向布局中拖拽添加素材4.页面定制完成后可以分享页面(TODO) 改进作为demo,目前还有

0

CSS中a:link、a:visited、a:hover、a:active的使用总结

前言伪类 伪元素 区别  可以理解为:伪类的效果可以通过添加一个实际的类来达到,而伪元素的效果则需要通过添加一个实际的元素才能达到。伪类用一个冒号来表示,而伪元素则用两个冒号来表示。 概述:link 选择器对指向未被访问页面的链接设置样式,即页面初始化加载完成的时候。:visited 选择器用于选取已被访问的链接,即已经访问过的链接。:hover 选择器用于设置鼠标指针浮动到链接上时的样式,即鼠

0

CSS3媒体查询@media功能使用总结

前言  媒体查询包含一个可选的媒体类型和零或多个表达式来限制使用媒体特性的样式表范围,这些表达式会被解析为true或false。如果媒体查询中指定的媒体类型匹配展示文档所使用的设备的类型以及所有的表达式的值都是true,那么该媒体查询的结果就是true。例如width,height,color。CSS3中的Media queries让内容的呈现可以只针对特定范围的输出设备而不必去改变内容本身。

0

使用原生js实现元素拖拽功能

前言  本篇仅对拖拽过程中核心几个事件监听的写法进行小结,不涉及页面样式效果的展现。 实现1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818

0

DOM级别

DOM目标  DOM标准的目标是让“任何一种程序设计语言”能操控使用“任何一种标记语言”编写出的“任何一份文档”。“操控”具体含义为能通过DOM提供的API对文档的内容、结构、样式进行访问和修改。 DOM分类 DOM核心:针对任何结构化文档的标准模型 DOM XML :只针对XML文档的标准模型 DOM HTML:只针对HTML文档的标准模型 DOM级别DOM Level 0  实际上没有

0

使用IntelliJ IDEA构建并运行Java Web的maven项目

前言  相比于eclipse,IntelliJ IDEA的功能更加丰富,稳定。本文对使用IntelliJ IDEA构建运行一个基于maven管理的Java Web项目的过程进行记录。 项目代码导出 菜单栏选择VCS -> Checkout from Version Control -> Subversion 新建关联的SVN仓库,一般是填写内网部署的代码管理服务器地址 根据实际情

0

CSS3的pointer-events属性及典型应用

概念  pointer-events是CSS3中的属性,最常用的有以下两个取值:1pointer-events:none|auto   设置“pointer-events:none”后元素永远不会成为鼠标事件的target。但是,当其后代元素的pointer-events属性指定其他值时,鼠标事件可以指向后代元素,在这种情况下,鼠标事件将在捕获或冒泡阶触发父元素的事件侦听器。 应用1  当已经

0

JavaScript的call()、apply()、bind()方法对比总结

前言  JavaScript中的函数其实就是一种对象。函数对象也有自己的很多方法。其中,call()方法和apply()方法就是两个用来间接调用函数的方法。两个方法都允许显式地指明调用时的上下文环境(即this的值)。也就是说,这给我们提供了一种自由—任何函数可以作为任何对象的方法来进行调用。并且,两个方法也都允许显式地指明调用时需要用到的实参。函数经call()或apply()调用后会立即执行

0

使用HTML5的FileAPI完成图片预览上传

前言  html5提供了File API,可以很好用于图片上传和本地预览的使用场景。 html结构以下html片段表示了图片上传组件的文档结构,依赖Amaze UI样式框架。123456789101112131415161718192021222324252627282930313233343536<div class="am-g"> <div class="am-for

0

jQuery中$.when()方法和deferred对象相关总结

概述jQuery.when( deferreds )1.提供一种方法来执行零个或多个对象的回调函数, Deferred(延迟)对象通常表示异步事件。 2.如果没有参数传递给 jQuery.when(),它会返回一个resolved状态的Promise。 3.如果传递一个非Deferred或Promise对象给jQuery.when(),那么它会被当作是一个被解决(resolved)的延迟对象,并

0

使用JavaScript实现三级联动和实时搜索

前言  本篇仅对三级联动和实时搜索的核心给出说明,对于页面设计、整个工程结构等不做说明。 三级联动根据交互操作异步触发获取第一列数据12345678910111213141516171819202122232425262728293031323334353637383940//异步请求第一列数据-可选指标名称 $.ajax({ type: "POST", async:

0

CSS的颜色空间-Color Name、HEX、RGB、RGBA、HSL、HSLA

前言  通过CSS指定元素颜色是经常遇到的操作。在CSS中有多种表示颜色的方式。其中,RGBA、HSL、HSLA这三个是CSS3中新增的颜色表示方法。CSS提供了很多和color相关的属性,常用的主要有color、background-color、border-color、text-decoration-color等。下面的说明,均以对background-color的赋值为例。 Color

0

JavaScript的caller属性和callee属性对比总结

背景  要说这两个方法,必须先说另一个东西—实参对象(arguments)。标识符arguments是指向实参对象的引用。当传入某个函数的参数个数超过函数定义时指定的形参个数时,默认的处理方法是自动忽略多出来的参数。也就是说,默认这不会引起错误。但是这会有另一个问题:无法获取多出来的参数的引用了(无法知道多出来的参数具体值是什么)。这也正是实参对象arguments可以解决的问题。通过argum

0

leetcode [#92]

题目 Reverse a linked list from position m to n. Do it in-place and in one-pass. Example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL. Example:Giv

0

leetcode [#9]

题目 Determine whether an integer is a palindrome. Do this without extra space. Some hints:Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note

0

leetcode [#88]

题目 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additi

0

leetcode [#86]

题目 Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each o

0

leetcode [#82]

题目 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example:Given 1->2->3->3->4->4->5, return 1->2-

0

leetcode [#83]

题目 Given a sorted linked list, delete all duplicates such that each element appear only once. Example:Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. 解决方案

0

leetcode [#8]

题目 Implement atoi to convert a string to an integer. HintCarefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cas

0

leetcode [#75]

题目 Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers

0

leetcode [#7]

题目 Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 解决方案1234567891011public class Solution { public int reverse(int x) { String s = Str

0

leetcode [#67]

题目 Given two binary strings, return their sum (also a binary string). Examplea = “11”b = “1”Return “100”. 解决方案123456789101112131415161718192021222324252627282930313233343536373839404142434445464748

0

leetcode [#66]

题目 Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. 解决方案1234567891011121

0

leetcode [#62]

题目 A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the

0

leetcode [#58]

题目 Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, return the length of last word in the string. If the last word does not exist, return 0. ExampleGiven s = “H

0

leetcode [#53]

题目 Find the contiguous subarray within an array (containing at least one number) which has the largest sum. Examplegiven the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the l

0

leetcode [#6]

题目 The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) 123P A H NA P L S

0

leetcode [#463]

题目 You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is complet

0

leetcode [#448]

题目 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Coul

0

leetcode [#415]

题目 Given n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of th

0

leetcode [#438]

题目 Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be lar

0

leetcode [#409]

题目 Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example “Aa” is not con

0

leetcode [#414]

题目 Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example1:Input: [3, 2, 1]

0

leetcode [#415]

题目 Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0

0

leetcode [#400]

题目 Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … Example1:Input:3 Output:3 Example2:Input:11 Output:0 Explanation:The 11th digit of the sequence 1, 2, 3, 4,

0

leetcode [#396]

题目 Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a “rotation function” F on A as follow: F(k) =

0

leetcode [#394]

题目 Given an encoded string, return it’s decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is

0

leetcode [#383]

题目 Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines

0

leetcode [#389]

题目 Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was ad

0

leetcode [#374]

题目 We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I’ll tell you whether the number is higher

0

leetcode [#36]

题目 解决方案12 注意事项 以下方法是错误的:12345678910111213141516171819202122import java.util.HashSet;public class Solution { public boolean isValidSudoku(char[][] board) { for(int i = 0; i <

0

leetcode [#38]

题目 The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11.11 is read off as “two 1s” or 21.21 is read off as “one 2, the

0

leetcode [#350]

题目 Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as many times a

0

leetcode [#35]

题目 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array

0

leetcode [#349]

题目 Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result must be unique. The result can b

0

leetcode [#344]

题目 Write a function that takes a string as input and reverse only the vowels of a string. Example:Given s = “hello”, return “holle”.Given s = “leetcode”, return “leotcede”. Note:The vowels does not i

0

leetcode [#344]

题目 Write a function that takes a string as input and returns the string reversed. Example:Given s = “hello”, return “olleh”. 解决方案1234567public class Solution { public String reverseString(S

0

leetcode [#299]

题目 You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint

0

leetcode [#341]

题目 Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list – whose elements may also be integers or other lists. Example:Given the list [[1,

0

leetcode [#326]

题目 Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion? 解决方案12345678910111213public class Solution { publ

0

leetcode [#292]

题目 You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be

0

leetcode [#290]

题目 Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Exam

0

leetcode [#283]

题目 Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. Example:given nums = [0, 1, 0, 3, 12], after calling your func

0

leetcode [#278]

题目 You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on

0

leetcode [#28]

题目 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 解决方案123456789101112131415161718192021222324252627282930public class

0

leetcode [#263]

题目 Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. ExampleFor example, 6, 8 are ugly while 14 is not ugl

0

leetcode [#268]

题目 Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. For example: Given nums = [0, 1, 3] return 2. NoteYour algorithm should run in l

0

leetcode [#26]

题目 Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place wit

0

leetcode [#27]

题目 Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. Th

0

leetcode [#258]

题目 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one d

0

leetcode [#242]

题目 Given two strings s and t, write a function to determine if t is an anagram of s. Example:s = “anagram”, t = “nagaram”, return true.s = “rat”, t = “car”, return false. Note:You may assume the stri

0

leetcode [#24]

题目 Given a linked list, swap every two adjacent nodes and return its head. Example:Given 1->2->3->4, you should return the list as 2->1->4->3. Note:Your algorithm should use only co

0

leetcode [#237]

题目 Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node

0

leetcode [#237]

题目 Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O

0

leetcode [#234]

题目 Given a singly linked list, determine if it is a palindrome. 解决方案1234567891011121314151617181920212223242526272829303132/** * Definition for singly-linked list. * public class ListNode { *

0

leetcode [#232]

题目 Implement the following operations of a queue using stacks. push(x) – Push element x to the back of queue. pop() – Removes the element from in front of queue. peek() – Get the front element. empt

0

leetcode [#231]

题目 Given an integer, write a function to determine if it is a power of two. 解决方案1234567891011public class Solution { public boolean isPowerOfTwo(int n) { if(n < 0) return fal

0

leetcode [#219]

题目 Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. 解决方

0

leetcode [#226]

题目 解决方案1234567891011121314151617181920212223/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x)

0

leetcode [#225]

题目 Implement the following operations of a stack using queues. push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. empty() – Return whe

0

leetcode [#226]

题目 解决方案12345678910111213public class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int s1 = (C - A) * (D - B); int s2 = (G

0

leetcode [#22]

题目 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ “((()))”, “(()())”, “(())()”, “()(())”,

0

leetcode [#217]

题目 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every elemen

0

leetcode [#21]

题目 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 解决方案123456789101112131415161718192021222324252627282

0

leetcode [#206]

题目 Reverse a singly linked list. 解决方案123456789101112131415161718192021222324252627282930313233/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode n

0

leetcode [#204]

题目 Count the number of prime numbers less than a non-negative number, n. 解决方案12345678910111213141516171819public class Solution { public int countPrimes(int n) { if(n <= 2) r

0

leetcode [#205]

题目 Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with anothe

0

leetcode [#203]

题目 Remove all elements from a linked list of integers that have value val. Example:Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6Return: 1 –> 2 –> 3 –> 4 –> 5 解决方案123

0

leetcode [#202]

题目 Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the square

0

leetcode [#20]

题目 Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]{}” are all valid

0

leetcode [#19]

题目 Given a linked list, remove the nth node from the end of list and return its head. Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the

0

leetcode [#189]

题目 Rotate an array of n elements to the right by k steps. Example:with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note:Try to come up as many solutions as you can, ther

0

leetcode [#179]

题目 Given a list of non negative integers, arrange them such that they form the largest number. Example:Given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very lar

0

leetcode [#171]

题目 Given a column title as appear in an Excel sheet, return its corresponding column number. Note:A -> 1B -> 2C -> 3…Z -> 26AA -> 27AB -> 28 解决方案1234567public class Solution

0

leetcode [#172]

题目 Given an integer n, return the number of trailing zeroes in n!. Note:Your solution should be in logarithmic time complexity. 解决方案12345678910public class Solution { public int trailingZer

0

leetcode [#169]

题目 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element a

0

leetcode [#168]

题目 Given a positive integer, return its corresponding column title as appear in an Excel sheet. Example:1 -> A2 -> B3 -> C…26 -> Z27 -> AA28 -> AB 解决方案123456789101112131415161718

0

leetcode [#167]

题目 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbe

0

leetcode [#165]

题目 Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assume that the version strings are non-empty

0

leetcode [#155]

题目 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get

0

leetcode [#160]

题目 Write a program to find the node at which the intersection of two singly linked lists begins. Example:the following two linked lists:A: a1 → a2 ↘ c1

0

leetcode [#142]

题目 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. 解决方案12345678910111213141516171819202122232425/** * Definition for singly-linked list. * class List

0

leetcode [#147]

题目 Sort a linked list using insertion sort. 解决方案12345678910111213141516171819202122232425262728293031323334353637383940/** * Definition for singly-linked list. * public class ListNode { *

0

leetcode [#141]

题目 Given a linked list, determine if it has a cycle in it. 解决方案12345678910111213141516171819202122232425/** * Definition for singly-linked list. * class ListNode { * int val; * ListNod

0

leetcode [#14]

题目 Write a function to find the longest common prefix string amongst an array of strings. 解决方案1234567891011121314151617181920212223242526272829303132public class Solution { public String lo

0

leetcode [#13]

题目 Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 解决方案1234567891011121314151617181920212223242526272829303132333435363738394041424344454

0

leetcode [#136]

题目 Given an array of integers, every element appears twice except for one. Find that single one. 解决方案123456789101112131415161718import java.util.Hashtable;public class Solution { public int

0

leetcode [#125]

题目 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Example“A man, a plan, a canal: Panama” is a palindrome.“race a car” is not a palindro

0

leetcode [#122]

题目 Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy o

0

leetcode [#121]

题目 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock)

0

leetcode [#119]

题目 Given an index k, return the kth row of the Pascal’s triangle. Example:given k = 3,Return [1,3,3,1]. 解决方案1234567891011121314151617181920212223public class Solution { public List<Integ

0

leetcode [#118]

题目 Given numRows, generate the first numRows of Pascal’s triangle. Example:given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]] 解决方案1234567891011121314151617181920publi

0

leetcode [#1]

题目 Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution. Example:Given nums = [2, 7

0

leetcode [#104]

题目 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 解决方案123456789101112131415161718192

0

【转】HTTPS与SSL(下篇)

原文链接:http://www.jianshu.com/p/c03f47e7b9de#感谢原作者!(学长这个系列的文章已被“开发者头条APP”收录为头条文章)

0

【转】HTTPS与SSL(上篇)

原文链接:http://www.jianshu.com/p/eafa5f19cb0b#感谢原作者!(学长这个系列的文章已被“开发者头条APP”收录为头条文章)

0

JavaScript数组方法对比总结

前言  本文对JavaScript中数组类型(Array)的常用方法进行总结,主要包括其API,使用示例和是否直接操作/修改原数组的分析。文章最后会对ECMAScript5中提供的数组方法进行小结。 join()作用  将数组元素衔接为字符串。参数  array.join()  array.join(separator)  separator: 在返回的拼接字符串中,用以连接原来数组元素的分隔

0

Cookie相关总结

前言  本篇简单总结cookie的概念,作用,应用,实现案例等要点,关于大段的介绍,就不再重复了,网上有很多可以参考。而且cookie相关是一个很大的话题,这里只是简单小结,主要包括:  1.cookie相关介绍  2.cookie安全性问题  3.javascript对cookie的操作与使用  4.cookie与session的对比分析  5.cookie在实际开发中的使用 直观感受  c

0

使用JavaScript实现轮播图效果(JavaScript运动框架案例)

前言  轮播图组件是一种网站中常见的表现形式。常用于广告位,头条新闻等重要信息的展示而且将图片和信息结合起来,引人注意。轮播图最重要的自然是“轮播”,也就是要让页面中的DOM元素“动”起来。这就自然需要先简单提一下JavaScript的运动框架。 JavaScript运动框架简介  JavaScript运动框架就是指利用js和DOM元素配合,利用js的相关函数以一定的频率操作改变DOM元素的位置

0

Restful风格的API

关于restful API的设计是一个很重要的问题,这里给出3篇高质量的文章以供参考。RESTful 架构风格概述 RESTful API 编写指南 阮一峰 理解RESTful架构

0

Array.prototype.slice.call()的典型应用

作用  一句话来讲,这是一种将类数组对象转换为真正数组的方法。很多时候我们会遇到“类数组对象”,比如在操作DOM元素的时候,查询符合某种class的DOM节点会返回一个NodeList,它就是一个类数组对象。真正数组的很多成员方法不能直接用于类数组对象,因此就需要将其转换为真正的数组。 示例123456789Function.prototype.bind = function(context)

0

JavaScript双向选择器的实现

前言  双向选择器是网站中经常使用的一种组件,适合于要求用户输入固定的一个或多个标签内容的场景,这种格式比普通input输入框的交互方式更加友好,而且可以防止因用户输入的随意性而导致的其他多余工作(比如表单验证)甚至错误。 效果  在说具体细节之前,可以先看一下效果,下图中就实现了一个最基本的双向选择器。 注意事项1.以上组件的编写没有基于原生的CSS,而是引入了AmazeUI框架,利用了

0

CSS[内容盒模型]和[边框盒模型]的对比分析

盒模型概述  盒模型是CSS中的一个重要概念和组成部分,直接决定了页面的基本布局。下图是一张网上常见的关于CSS盒模型的立体图,很好的解释了盒模型中的基本概念。  不同种类和版本的浏览器对于width, height, padding, border, margin的解析有所不同,导致同样的CSS代码在不同浏览器上有不相同的效果。本文对此进行小结。  所有HTML元素可以看作盒子,在CSS中,”

0

Session相关总结

前言  本篇简单总结session的概念,作用,应用,实现案例等要点,关于大段的介绍,就不再重复了,网上有很多可以参考。而且session相关是一个很大的话题,这里只是简单小结,主要包括以下几个大的方面:  1.直观感受  2.session相关介绍  3.session安全性问题  4.session的不同实现方式  5.cookie与session的对比分析  6.session在PHP开发

0

胖URL(fat url)

前言  HTTP本身是匿名/无状态的请求/响应协议,为了能够进行客户端识别,发展出了很多种解决方案,胖URL就是其中一种用户识别机制,它是一种在URL中嵌入识别信息的技术。 定义  服务端可以通过为每个用户生成特定版本的URL来追踪用户身份。通常的做法是在URL开始或结束的地方增加一些状态信息。用户浏览站点时,web服务器会动态生成一些超链,继续维护URL中的状态信息。这种改动后的URL就被称

0

《JavaScript权威指南》中文版P204纠错

  中文版《JavaScript权威指南》第六版P204中,讲到使用构造函数定义类时,提到“Range()构造函数是通过new关键字调用的(在示例代码的末尾)”,如下图:   找了半天没看出来示例代码中到底是怎么通过new关键字调用的,于是,查看了一下原书第六版,如下图:   好吧,原来中文版这里出现了一点小错误,直接将前一页P203示例代码“用原型对象定义方法”中的代码粘贴过来了,怪不得

0

JavaScript的null和undefined对比总结

前言  说到这两个类型,首先应该从整体上明确一下JavaScript中提供的数据类型。  JavaScript中的数据类型分为两类:原始类型和对象类型。  其中,原始类型又可以细分为如下5类:数字,字符串,布尔值,null,undefined。  null和undefined都表示一种“空缺”的意思,但具体还有很多细节不同。 null类型检测对null使用typeof检测,可得: 说明  由以

0

《JavaScript 权威指南》P147的一处分析

情景  在《JavaScript权威指南 第六版 中文版》P147,讲到稀疏数组时,书中给出如下的分析和例子:  读完后感觉第一个红框和第二个红框中的表述不是很清楚,有些矛盾。于是在chrome浏览器的控制台进行测试,结果如下: 第一个红框对应结果 第二个红框对应结果 第三个红框对应结果也就是说实测结果与书中第一个红框中的蓝色小框表述相反:0 in a1输出的值是false。 分析  以下

0

CSS相关单位(pt,px,PPI,DPI,em,rem)

单位介绍 pt:磅(point),绝对单位,印刷行业常用,等于1/72英寸(即0.03526厘米,1英寸 = 2.54厘米)。 px:像素(pixel),相对长度单位,相对于显示器屏幕分辨率而言。 PPI:像素密度(Pixel Per Inch),每英寸所拥有的像素数量。因此PPI数值越高,即代表显示屏能够以越高的密度显示图像。当然,显示的密度越高,拟真度就越高。 DPI:点数密度(Dot

0

通用的HTML文档DOM树遍历函数

前言  本篇记录《JavaScript权威指南》中提供的通用性的DOM结构遍历函数,这是十分常用的场景,可以获取除了Text节点以外的全部文档节点。 实现parent函数 返回元素e的第n层祖先元素,如果不存在则返回null 如果n===0;返回e本身;n===1,返回父节点,以此类推123456function parent(e, n) { if (n === undefin

0

JavaScript的闭包案例---2

前言  接续之前的一篇JavaScript的闭包案例—1,加深对《JavaScript权威指南》P187的理解。 描述  使用闭包,可以实现共享私有状态,实现私有存取器属性。本质上就是在同一个作用域链上定义了两个或多个闭包,来共享同样的私有变量。这是十分重要的一种应用,但是要十分小心因为这种做法将那些本不希望共享的变量共享给了其他闭包,这会造成严重的错误并让我们不解。  假设有这样的需求:需要

0

setTimeout与setInterval的对比与互相实现

案例 setTimeout和setInterval对比 另外,根据网上一张关于此问题比较流行的图:1234567function click() { // code block1... setInterval(function() { // process ... }, 200); // code block2 } setInterval可能会存在的问题

0

JavaScript的闭包案例---1

背景  闭包是JavaScript中的一个重要概念。  JavaScript采用词法作用域,函数的执行依赖于变量作用域,这个作用域是在函数定义时决定的,而不是函数调用时决定的。函数对象可以通过作用域链相互关联起来,函数体内部的变量都可以保存在函数作用域内,这就是闭包的特性。

0

使用JavaScript实现数组去重的4种方法及性能比较

方法一思路:创建一个新的结果数组,遍历原数组,利用数组indexOf()方法,判断原数组当前值是否在结果数组中存在,如果存在则跳过,否则压入结果数组。12345678910 function removeDuplicatedItem(ar) { var ret = []; for (var i = 0, j = ar.length; i < j; i++)

0

jQuery的ajax()方法详细分析

前言  ajax,即“Asynchronous Javascript And XML”(异步JavaScript和XML),是一种异步加载数据的Web交互方法,在网页开发中使用十分普遍,实现局部刷新以达到更好的交互效果是ajax的典型应用。 核心  $.ajax(即jQuery.ajax),是jQuery库进行的一次封装。其核心实现是利用了JavaScript中的XMLHttpRequest对

0

使用JavaScript实现非法输入字符实时过滤

前言  表单提交是一项常见操作,对于输入内容的合法性必须在前后端都做验证才能保证可靠性。表单验证有很重要的意义,除了防止注入攻击之类的安全问题外,有时如果不能正确的进行验证,可能会使合法的页面渲染受到影响。比如在实际开发中遇到的一种问题,jsp页面使用JSTL库自定义标签渲染后台传来的数据时,需要将这组数据作为参数传入相应点击事件的回调函数,如果参数中一旦也有双引号”,就会导致解析错误—oncl

0

使用JavaScript实现金额格式化转换

前言  实现金额数字的每三位打”,”,便于识别金额大小。 实现12345678910111213//s: 希望转换的金额数字;n:希望保留的小数位数function formatMoney(s, n) { n = n > 0 && n <= 20 ? n : 2; //正则/[^\d\.-]/g表示去除传入字符串中非数字,非小数点,非负号以

0

使用JavaScript实现短信重发倒计时

主要html结构以下html片段表示了重发倒计时组件的文档结构,依赖Amaze UI样式框架。 onclick=”btnSendMsgAgain();return false;”中的return false作用:验证码是位于form表单中的,点击该按钮的作用是发送验证码,而不是提交表单,return false为了彻底阻止元素的默认事件。 123<div class="am-u-sm-

0

HTML转义字符

背景  HTML转义字符又称字符实体。一些字符在HTML中有特殊的含义,比如小于号”<”已经用于定义HTML标签的开始。而这些标签在渲染出的html页面是不会显示出来的,如果我们希望浏览器正确地显示这些字符,我们必须在HTML源码中插入字符实体。  字符实体有三部分,而且有两种写法:

0

【转·译】编写不唐突的JavaScript(unobtrusive-javascript)的七条准则

前言  “unobtrusive javascript—不唐突的JavaScript”最早是从《JavaScript权威指南》中看到,13.2节最先出现了这个概念。我认为也可以描述成“优雅的JavaScript”,指的是那些拥有良好的编码规范,易于维护的JavaScript写法和注意事项。进而在网上看到了这篇“编写不唐突的JavaScript(unobtrusive-javascript)的七条

0

【首篇】记录本博客www.gcidea.info的搭建过程

前言  在探索各类技术的道路上,我从无数博客中学到了很多东西。这些博文中往往都是大家在实践过程中遇到的各类问题最真实的反映和汇总,因此有很强的参考性。  但同时,由于环境、版本、配置等等方面的不同,一些问题在每个人面前又有着不同的具体表现,让人摸不着头脑。因此,我也十分乐意分享出一些自己的经验,让大家在遇到问题时多一些尝试办法。当然,能做到这一点自然是最好了,更多的,我是想借用这样一个平台记录自己在技术学习过程中的点点滴滴,是一种总结,也是一种约束。  平台的选择考虑过CSDN,博客园等,可以有更多的人交流。但反而一想,搭建博客本身就是一次探索尝试的过程,因此我选择最终选择了“自己动手”,同时,在一个相对安静的环境中,也好“修炼”自己。