X
X
X
常用的 class、id、属性 选择器都可以使用 document.querySelector
或 document.querySelectorAll
替代。区别是
document.querySelector
返回第一个匹配的 Elementdocument.querySelectorAll
返回所有匹配的 Element 组成的 NodeList。它可以通过 [].slice.call()
把它转成 Array[]
,但 document.querySelector
返回 null
,注意空指针异常。当找不到时,也可以使用 ||
设置默认的值,如 document.querySelectorAll(selector) || []
注意:
document.querySelector
和document.querySelectorAll
性能很差。如果想提高性能,尽量使用document.getElementById
、document.getElementsByClassName
或document.getElementsByTagName
。
// jQuery
$('selector');
// Native
document.querySelectorAll('selector');
/**
* 判断字符串是否为 Json 格式
*
* @param string $data Json 字符串
* @param bool $assoc 是否返回关联数组。默认返回对象
*
* @return array|bool|object 成功返回转换后的对象或数组,失败返回 false
*/
function isJson($data = '', $assoc = false) {
$data = json_decode($data, $assoc);
if (($data && is_object($data)) || (is_array($data) && !empty($data))) {
return $data;
}
return false;
}
使用 window 对象的 open()
方法可以打开一个新窗口。用法如下:
window.open(url, target, features)
该方法返回值为新创建的 window 对象,使用它可以引用新创建的窗口。
url
可选字符串,声明新窗口需要载入的 url 地址,可以是 web 上的 html 页面也可以是图片文件或者其他任何浏览器支持的文件格式。
如果省略,或者为空,则新窗口就不会显示任何文档。
target
可选字符串,声明新窗口的名称。该字符串可以用来作为超链接 <a> 或表单 <form> 元素的目标属性值。字符串中不能含有空白字符。
如果该参数指定了一个已经存在的窗口,那么 open() 方法就不再创建一个新窗口,而只是返回对指定窗口的引用,在这种情况下,features 参数将被忽略。
features
可选字符串,声明了将要打开的窗口的一些特性 (窗口功能和工具栏),具体说明如下表所示。
如果省略该参数,新窗口将具有所有标准特征。
在 jQuery 中,获取元素高度的方法有 3 个:height()
、innerHeight()
、outerHeight()
。
元素的盒模型: height
(高度)、padding
(内边距)、margin
(外边距)、border
(边框)。
height()
:
$(window).height(); // 返回浏览器视口的高度
$(document).height(); // 返回HTML文档的高度
/*!
* jQuery lightweight plugin boilerplate
* Original author: @ajpiano
* Further changes, comments: @addyosmani
* Licensed under the MIT license
*/
// the semi-colon before the function invocation is a safety
// net against concatenated scripts and/or other plugins
// that are not closed properly.
;(function ( $, window, document, undefined ) {
// undefined is used here as the undefined global
// variable in ECMAScript 3 and is mutable (i.e. it can
// be changed by someone else). undefined isn't really
// being passed in so we can ensure that its value is
// truly undefined. In ES5, undefined can no longer be
// modified.
// window and document are passed through as local
// variables rather than as globals, because this (slightly)
// quickens the resolution process and can be more
// efficiently minified (especially when both are
// regularly referenced in your plugin).
// Create the defaults once
var pluginName = 'defaultPluginName',
defaults = {
propertyName: "value"
};
// The actual plugin constructor
function Plugin( element, options ) {
this.element = element;
// jQuery has an extend method that merges the
// contents of two or more objects, storing the
// result in the first object. The first object
// is generally empty because we don't want to alter
// the default options for future instances of the plugin
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype.init = function () {
// Place initialization logic here
// You already have access to the DOM element and
// the options via the instance, e.g. this.element
// and this.options
};
// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName,
new Plugin( this, options ));
}
});
}
})( jQuery, window, document );
(function( $ ){
var methods = {
init : function( options ) { // THIS },
show : function( ) { // IS },
hide : function( ) { // GOOD },
update : function( content ) { // !!! }
};
$.fn.tooltip = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );
如果是MySQL数据库,可进入主机的数据库管理后台,找到博客数据库中的typecho_users
表,修改password
的值为e10adc3949ba59abbe56e057f20f883e
(相当于加密过的密码123456)。
如果使用Sqlite数据库,则先将数据库下载到本地,用数据库管理工具(如Navicat)按上述步骤修改,修改后再上传回虚拟主机。
完成后,用密码123456登录,进入到后台修改密码。
FROM_UNIXTIME(unixtime, format)
将时间戳转换为日期时间字符串UNIX_TIMESTAMP(date)
将指定的日期或者日期字符串转换为时间戳DATE_FORMAT(date, format)
根据参数对date进行格式化
select now(); 或 select current_timestamp(); //获得当前时间 格式:2016-01-12 23:19:43
select curdate(); 或 select current_date(); //获得当前时间 格式: 2016-01-12
select current_date()+0; //获得当前时间 格式: 20160112
select curtime(); 或 select current_time(); //获得当前时间 格式:23:19:43
URL.createObjectURL() 静态方法会创建一个 DOMString,其中包含一个表示参数中给出的对象的URL。这个 URL 的生命周期和创建它的窗口中的 document 绑定。这个新的URL 对象表示指定的 File 对象或 Blob 对象。
URL.createObjectURL(blob)和FileReader.readAsDataURL(file)很相似:
区别
<?php Typecho_Widget::widget('Widget_Stat')->to($stat); ?>
文章总数:<?php $stat->publishedPostsNum() ?>篇
分类总数:<?php $stat->categoriesNum() ?>个
评论总数:<?php $stat->publishedCommentsNum() ?>条
页面总数:<?php $stat->publishedPagesNum() ?>个
当前作者的文章总数:<?php $stat->myPublishedPostsNum() ?>篇