Category: Javascript /Jquery / React / Bootstrap / Web

JavaScript 无依赖jQuery 用法之Ajax Requests JavaScript without jQuery : You Don’t Need jQuery!

Ajax Requests Many developers who learned web development through a jQuery lens probably think that jQuery is doing something magical when you invoke the $.ajax method. That couldn’t be further from the truth. All of the heavy lifting is done by the browser via the XMLHttpRequest object. jQuery’s ajax is just a wrapper around XMLHttpRequest…

Chrome Extension: Chrome.storage 存储API简单使用 (缓存,cache)

有时候我们不满足于localStorage只能保存string的单调功能,那么试一试chrome.storage中存储多种类型的本领? *.本文中的操作实例仅仅使用storage.local,其他API都类似。 声明权限 { "permissions": ["storage"] } 保存数据 // chrome.storage.local.set函数需要两个参数,一个为存储对象,一个为回调函数 chrome.storage.local.set({ string: '可以存储字符串', array: ['或者', '数组'], object: {k: '或者', v: '对象'}, int: 111 }, function(){ console… Read More

Chrome Extension : 事件交互实例 (消息传递, sendMessage,connect,onConnect,onMessage)

alert.js alert('hello ' + document.location.href); manifest.json { "manifest_version": 2, "name": "Click to execute", "description": "Execute script after click in popup.html (chrome extension) http://stackoverflow.com/questions/20764517/execute-script-after-click-in-popup-html-chrome-extension.", "version": "1.0", "icons":… Read More

Javascript: 二维数组转一维数组(合并数组) Convert a 2D array to a 1D array

Here, I’m trying to convert arrToConvert to a 1D array. var arrToConvert = [[0,0,1],[2,3,3],[4,4,5]]; console.log(get1DArray(arrToConvert)); //print the converted array function get1DArray(2dArr){ //concatenate each element of the input into a 1D array, and return the output //what would be the best way to implement this function? }  … Read More

JavaScript: JSON对象 (JSON格式, JSON.stringify()和JSON.parse()的用法)

JSON格式 JSON格式(JavaScript Object Notation的缩写)是一种用于数据交换的文本格式,2001年由Douglas Crockford提出,目的是取代繁琐笨重的XML格式。 相比XML格式,JSON格式有两个显著的优点:书写简单,一目了然;符合JavaScript原生语法,可以由解释引擎直接处理,不用另外添加解析代码。所以,JSON迅速被接受,已经成为各大网站交换数据的标准格式,并被写入ECMAScript 5,成为标准的一部分。 简单说,每个JSON对象,就是一个值。要么是简单类型的值,要么是复合类型的值,但是只能是一个值,不能是两个或更多的值。这就是说,每个JSON文档只能… Read More

jQuery管理ajax异步-deferred对象

今天跟大家分享一个jquery中的对象-deferred。其实早在jquery1.5.0版本中就已经引入这个对象了。不过可能在实际开发过程中用到的并不多,所以没有太在意。 这里先不说deferred的概念,我们先看一个例子。 还记得初学的时候,遇到一个实例,先是要ajax请求一个接口(a.json),从返回的数据中获得一个id1值。然后再请求一个接口(b.json)获得id2,最后需要对这两个id值同时进行操作。 错误解法 那个时候初学,首先想到的方案(现在想想,很傻很天真…) var id1, id2; $.ajax({ url: 'a.js', dataType: 'json', type: 'get',… Read More

JAVA: 解决报错Exception in thread “main” java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V

用到selenium webdiver的是,发现报错: Exception in thread “main” java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V 解决方法,在maven的porm.xml的配置文件中加载最新版的google guava <dependency> <groupId>com.google.g… Read More

JavaScript:复制的内容自动添加版权信息 How to automatically append text to text copied with JavaScript

There are two main ways to add extra info to copied web text. 1. Manipulating the selection The idea is to watch for the copy event, then append a hidden container with our extra info to the dom, and extend the selection to it. This method is adapted from this article by c.bavota. Check also jitbit‘s version for

Google App Scripts 自定义函数(custom function)笔记

1. 自定义函数不可以使用setValue(), 但是通过onOpen添加到menu上的fucntion可以使用setValue() 2. onEdit 可以使用setValue function onEdit(event) { var sheets = SpreadsheetApp.getActiveSpreadsheet(); var tab = event.source.getActiveSheet(); var cell = event.source.getActiveRange(); var target = cell.getA1Notation().toString(); var value = cell.getValue(); // on… Read More

使用jQuery和Pure.CSS创建一个可编辑的表格

使用开源组件真的可以容易又快速地为网站和app构建强大的前端元素。在本教程中,我会告诉你如何使用PureCSS和jQuery轻松地创建可编辑的表格。 如果想看教程演示的话,请点击这里查看。 开始 你要做的第一件事情是,在你的服务器或本地硬盘上创建一个index.html文件。粘贴以下基本代码到新创建的文档中,然后保存。 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Editable table</title> <style> body{ paddi… Read More

2016十大优秀jQuery插件推荐

当有限的开发知识限制了设计进展,你无法为自己插上创新的翅膀时,jQuery可以扩展你的视野。本文将推荐从jQuery网站的Plugin频道中推选出的近期十款优秀jQuery插件。 1. jQuery URL Shortener 正如名字所清晰表达的那样,该jQuery插件利用Google URL shortener API可将URL转化成短链接。 下载 | 演示 | 项目首页 2. Bootstrap Tokenfield Bootstrap Tokenfield是一款针对输入框的高级标签插件,可获取键盘输入焦点,支持复制—粘贴。 下载 | 演示 3. Retinize Retinize可将图片质量进行提升,以在Retina显示器上完美显示… Read More

jQuery .tmpl() 用法

参考效果: DEMO  下载: jquery-tmpl-master 动态请求数据来更新页面是现在非常常用的方法,比如博客评论的分页动态加载,微博的滚动加载和定时请求加载等。 这些情况下,动态请求返回的数据一般不是已拼好的 HTML 就是 JSON 或 XML,总之不在浏览器端拼数据就在服务器端拼数据。不过,从传输量方面来看,返回 HTML 不划算,而在 web 传输方面,现在更多的是使用 JSON 而不是 XML。 浏览器端根据 JSON 生成 HTML 有个很苦恼的地方就是,结构不复杂的时候还好,结构一复杂,就想死了,需要很小心很小心地写出几乎无法维护的 JavaScript 代码。 如同为解决 PHP 拼数据这方面的问题而有了 Smarty 这… Read More

Bootstrap 3: 菜单居中 Center content in responsive bootstrap navbar

先看上面图片的效果,下面是代码: .navbar .navbar-nav { display: inline-block; float: none; } .navbar .navbar-collapse { text-align: center; } Edit: if you only want this effect to happen when the nav isn’t collapsed surround it in the appropriate media query. 或者: @media (min-width: 768px) { .navbar .navbar-nav {