Skip to content

Instantly share code, notes, and snippets.

@callblueday
callblueday / enterEvents
Last active December 20, 2015 17:49
表单回车事件防止重复提交
document.onkeydown=function() {//捕捉回车
if (event.keyCode==13) {
checkFormValidate();
return false;
}
}
@callblueday
callblueday / google closure Key events
Last active December 20, 2015 17:59
getting the enter key to be handled on press in an input/textbox
goog.events.listen(element, goog.events.EventType.KEYPRESS, function(a) {
if(a.keycode === 13) {
doSomething();
}
});
@callblueday
callblueday / js毫秒转成日期
Last active December 20, 2015 19:18
格式化日期,将毫秒转化成字符串的快捷函数
/**
* Format Date
* usage:
* date2str(new Date(seconds*1000),"MM-dd hh:mm");
*/
date2str = function(x,y) {
var z = {M:x.getMonth()+1,d:x.getDate(),h:x.getHours(),m:x.getMinutes(),s:x.getSeconds()};
y = y.replace(/(M+|d+|h+|m+|s+)/g,function(v) {
return ((v.length>1?"0":"")+eval('z.'+v.slice(-1))).slice(-2)
});
@callblueday
callblueday / document Scroll method
Last active December 20, 2015 19:18
网页滚动条滚动加载函数
function (){
var times = 0;
//滚动条到网页头部的 高度,兼容ie,ff,chrome
var top = document.documentElement.scrollTop + document.body.scrollTop;
//网页的高度
var textheight = document.body.offsetHeight;
// 网页高度-top-当前窗口高度
if (textheight - top - window.innerHeight <= 50) {
if (times >= 20) {
return; //控制最大只能加载20次
@callblueday
callblueday / angularjs select
Last active December 20, 2015 21:39
angularjs select.you might as well define the array in your controller
<div ng-app>
<h2>Todo</h2>
<div ng-controller="QuarterController">
<select name="quarter" ng-model="Quarter"
ng-options="obj.value as obj.text for obj in [
{'value': 1,'text' : 'Q1'},{'value':2,'text':'Q2'},{'value':3,'text':'Q3'},{'value':4,'text':'Q4'}]">
</select>
</div>
</div>
//---- controller.js ----
$scope.pageNum = null;
$scope.currentPage = 0;
$scope.pageSize = 10;
/* get previous page data */
$scope.getPrevPage = function() {
$scope.currentPage = $scope.currentPage - 1;
}
第一种方法:
var timestamp = Date.parse(new Date());
结果:1280977330000
第二种方法:
var timestamp = (new Date()).valueOf();
@callblueday
callblueday / form submit forbidden
Created August 19, 2013 01:34
return false is better because it prevents the default behavior of the event and also prevents the page from bubbling up. Note that this is only correct in jQuery event handlers.
//使用return false来禁用 form的默认submit事件。
<form method="POST" action="" id="search-form">
<input type="text" name="keywords" />
<input type="submit" value="Search" id="sButton" onclick="loadXMLDoc('file.xml')" />
</form>
<script>
window.onload = function() {
document.getElementById("search-form").onsubmit = function() {
<A href="javascript:void(0)">click me</a>
//javascript:void(0) 不返回的意思
@callblueday
callblueday / input 输入挂起事件
Created August 19, 2013 02:41
当用户在输入框中输入停顿一段时间后,会执行函数
$(".location").bind("input", function() {
var $this = $(this);
var delay =250; // delay after last input
clearTimeout($this.data('timer'));
$this.data('timer', setTimeout(function(){
$this.removeData('timer');
doSomething();
}, delay));
});