function getTime(){ var getNowDate = new Date(); //获取当前日期时间 const nowYear = getNowDate.getFullYear(); let nowMonth = getNowDate.getMonth()+1; let nowDay = getNowDate.getDate(); if(nowMonth >= 1 && nowMonth <=9 ){ nowMonth = ‘0‘ + nowMonth; } if(nowDay >=1 && nowDay <=9 ){ nowDay = ‘0‘ + nowDay }else if(nowDay == 1){ nowDay = 30; nowMonth -= 1; } var nowDate = nowYear + ‘-‘ + now...
js 简繁转换 1function copy(ob) {2var obj=findObj(ob); if (obj) {3 obj.select();js=obj.createTextRange();js.execCommand("Copy");}4 }5 6function paste(ob) {7var obj=findObj(ob); if (obj) {8 obj.select();js=obj.createTextRange();js.execCommand("Paste");}9 } 1011function cut(ob) { 12var obj=findObj(ob); if (obj) { 13 obj.select();js=obj.createTextRange();js.execCommand("...
/*** js获得url内的参数* 返回值: string or undefined* 使用方法:$_GET[‘from‘]*/var $_GET = (function() {var search = location.search;if (search == ‘‘){return {};}search = search.split(‘?‘)[1];search = search.split(‘&‘);var get = {};for (var i in search){var j = search[i].split(‘=‘);get[j[0]] = j[1];}return get;})(); 原文:http://www.cnblogs.com/bossikill/p/3982067.html
<html><body><span>倒计时30分钟:</span><span id="clock">00:30:00:00</span></body></heml><script type="text/javascript">//秒表倒计时控制var normalelapse = 100; var nextelapse = normalelapse;var counter; var startTime;var start1 = clock.innerText; var finish = "00:00:00:00"; var timer = null; // 开始运行 function run() { counter = 0; // 初始化开始时间 startTime = new Date().va...
运用function实现阶乘 以往的做法是如下的 function factorial(num){if(num <= 1){return 1;}else{return num * factorial(num - 1);}}但是如果一旦函数名改变 函数内部的递归调用行数也要进行改变 重用性很不好所以可以使用function 内部的callee()方法,此方法是function 类型内部的一个属性,它是一个指针指向函数参数对象的函数,即callee所在函数的本身所以以后的阶乘可以这样写了 function factorial(num){if(num <= 1){ret...
substr(start, length)substring(from, to)slice(from, to)以上函数只传一个参数时,认为是起始位置,然后按照正方向截取substring的参数,始终按从小到大截取,传负数默认转换为0 总之,记住substr第二个参数传的是长度,substring会把负参数置为0, 原文:https://www.cnblogs.com/anqiang1995/p/10187222.html
下载地址:http://www.lanrentuku.com/js/quanping-1141.html 原文:http://www.cnblogs.com/KTblog/p/4713645.html
js setTimeout运用<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>无标题文档</title><script type="text/javascript">var timer; //全局变量var i=0; //变量初始化,全局变量 //定义函数:开始计时function start...
JS是松散类型的语言,这一点JS的对象表现得尤为突出。那么如何来确定JS对象的具体类型呢? 首先,我们可以使用typeof运算符确定其基本类型(number,object,function,undefined)。如果typeof运算符返回object我们再使用instanceof来确定该对象是否属于某个具体类型。 注意:typeof null得到object,而typeof undefined得到undefined,typeof 数组对象得到object,typeof 函数得到function。 o instanceof Type:判断对象o是否属于Typ...
JS字符串截取 “指定字符” 前面和后面的内容!var string= "07/12" var before = string.split(‘/‘)[0] var after = string.split(‘/‘)[1] console.log(before,after) // 07 12 原文:https://www.cnblogs.com/silent007/p/9306464.html
简单的js数组排序:<span style="font-size:18px"><script LANGUAGE=javascript> var arr=[112,6,3,77,33,11,4]; arr.sort(function(a,b){return a-b}); alert(arr.toString());//3,4,6,11,33,77,112 </script></span> 二元数组排序:<span style="font-size:18px"><script LANGUAGE=javascript> var aa=[]; aa[0]=["4","aa1"]; aa[1]=["3","aa2"]; aa[2]=["1","aa3"]; aa[3]=["2","aa4"]; aa.sort(function(a,b){return...
//直接跳转 window.location.href="b.html"; //返回上一级页面 window.history.back(-1); //返回下一级页面 window.history.go(-1); jq监听后退事件<script type="text/javascript">$(document).ready(function(e) { var counter = 0;if (window.history && window.history.pushState) {$(window).on(‘popstate‘, function () {window.history.pushState(‘forward‘, null, ‘#‘);window.history.forward(1);window.location.h...
1.我比js早一年2.web浏览器是ECMAScript实现的宿主环境之一。 其它实现ECMAScript的宿主环境包括Node和Adobe Flash3.ECMAScript主要规定js的组成部分:语法,关键字和保留字; 变量,数据类型;操作符,语句;类型,对象;4.dom 把整个页面映射成一个多节点结构。dom独立于平台原文:http://www.cnblogs.com/zdsBlog/p/6416167.html
一转眼,这2015年上半年就过去了,差不多一个月没有写博客了,"罪过罪过"啊~~。进入了七月份,也就意味着我们上半年苦逼的单身生活结束了,从此刻起,我们要打起十二分的精神,开始下半年的单身生活。大家一起加油~~ 一直以来,JavaScript处理异步都是以callback的方式,在前端开发领域callback机制几乎深入人心。在设计API的时候,不管是浏览器厂商还是SDK开发商亦或是各种类库的作者,基本上都已经遵循着callback的套路。近几...
for (var i=0;i<10;i++){console.log(Math.random().toFixed(2)*100) }这个代码中利用随机取数选取 两位小数去乘以100 我们可以看到有两个出现了误差其实对于浮点数的四则运算,几乎所有的编程语言都会有类似精度误差的问题,只不过在 C++/C#/Java 这些语言中已经封装好了方法来避免精度的问题,而 JavaScript 是一门弱类型的语言,从设计思想上就没有对浮点数有个严格的数据类型,所以精度误差的问题就显得格外突出。下面就分析下...