JavaScript获得指定对象的大小function objectSize(the_object) { /* function to validate the existence of each key in the object to get the number of valid keys. */ var object_size = 0;……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2506浏览 2209个赞
本范例演示了JS如何通过window.open函数打开一个新窗口,及其参数设置function open_window(url){ var wparams = 'toolbar=0,location=0,directories=0,status=0,menubar=0,'; wparams += ……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2510浏览 2653个赞
这段代码用了一个非常巧妙的方法清空数组var myArray = ["one", "two", "three"];// console.log( myArray ) => ["one", "two", "three"]myA……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2154浏览 1202个赞
JavaScript获得url查询参数function getQueryVariable(variable){ var query = window.location.search.substring(1); var vars = query.split("&"); for (va……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2382浏览 2616个赞
只要给定Class,就能找到拥有这些class的元素function getElementsByClass(node,searchClass,tag) { var classElements = new Array(); var els = node.getElementsByTagName(tag); // use "*&q……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3176浏览 2471个赞
JS获取页面的宽度和高度,窗口的宽度和高度,返回一个数组//// getPageSize()// Returns array with page width, height and window width, height// Core code from - quirksmode.org// Edit for Firefox by pHaez……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3012浏览 799个赞
JavaScript函数参数默认值// Combiner of passed arguments and defaults (usable with any function)Object.prototype.combine = function(_args){ for(var i in this) { if(typeof _args[i……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2552浏览 2543个赞
这段js代码通过每天在不同时段自动更换网页调用的样式表,实现更换皮肤的功能。<script type="text/JavaScript"><!--function getStylesheet() { var currentTime = new Date().getHours(); if ……继续阅读 » 水墨上仙 6年前 (2021-03-12) 1496浏览 248个赞
JavaScript检测IE浏览器版本的代码<script type="text/javascript">if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x; var ieversion=new Number(RegExp.$……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3473浏览 724个赞
JavaScript随机从数组读取一项数据function write_quote() { var quotes = [ 'no animals were harmed while making this page', 'made in ulm', ……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2752浏览 1750个赞
JavaScript格式化数字为货币格式输出,如:100返回100.00,1.4返回1.40,88.776返回88.78function CurrencyFormatted(amount) { var i = parseFloat(amount); if(isNaN(i)) { i = 0.00; } var minus = '……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3044浏览 1201个赞
HTML5的搜索框写法,在HTML4时代,弄个搜索框要实现一些基本功能都需要JS的辅助,HTML5做了很多HTML4应该做但是没有做的事情。<form><p><label>Search:<input name=search autofocus /></label></p><……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2955浏览 2678个赞
javascript读取java变量import java.awt.*; import java.applet.*; public class InJava3 extends Applet{ public int iJava = 123; public String sJava = "String from ……继续阅读 » 水墨上仙 6年前 (2021-03-12) 1978浏览 1467个赞
JS输出一个随机数函数function RandomNumber(){ return Math.ceil(Math.random() * 85);}……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3174浏览 2752个赞
js中修改当前窗口大小的方法function resize_window(){ // move the window to 0,0 (X,Y) window.moveTo(0, 0); // resize the window to 800x600 window.resizeTo(800, 600); } ……继续阅读 » 水墨上仙 6年前 (2021-03-12) 1735浏览 2386个赞
JavaScript判断数组是否包含指定元素function in_array( what, where ){ var a=false; for(var i=0;i<where.length;i++){ if(what == where[i]){ a=true; break; } } return a……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3555浏览 2379个赞
HTML5轻松实现拖拽效果的演示范例<!DOCTYPE HTML><html><head><style type="text/css">#div1, #div2{float:left; width:100px; height:35px; margin:10px;padding……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3389浏览 2972个赞
使用html的标记返回顶部,需要在顶部添加一个标记,本代码靠js实现,无需顶部标记<!------> <script type="text/javascript"> function init(){ document.getElementById('gtop').oncli……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2100浏览 1803个赞
一个计算多个参数总和的JS函数,可以提供任意多个参数,计算出总和var sum = function() { var args = toArray.apply(null, arguments); // alert(args.length); if (args.length == 1) return args[……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2836浏览 1359个赞
纯JavaScript实现的淡入淡出效果,无需jQuery一类的框架,非常不错。function opacity(id, opacStart, opacEnd, millisec) { //speed for each frame var speed = Math.round(millisec / 100); var timer = 0; //……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2199浏览 1152个赞
javascript输出格式化后的数组String.prototype.print_f = function() { var formatted = this; for (var i = 0; i < arguments.length; i++) { var regexp = new RegExp('\\……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2477浏览 112个赞
这段代码可以在客户端检测常用的操作系统类型//OS DETECTION...var OSName="Unknown OS";if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";if (navigator.appVer……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3074浏览 1324个赞
本js代码通过对js对象进行各方面的比较来判断两个对象是否相等Object.equals = function( x, y ) { // If both x and y are null or undefined and exactly the same if ( x === y ) { retu……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2304浏览 2161个赞
JS通过navigator对象检测浏览器的类型,这个函数可以直接用在你的项目中,非常方便function whichBrs() { var agt=navigator.userAgent.toLowerCase(); if (agt.indexOf("opera") != -1) return 'Opera'……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3160浏览 2040个赞
jQuery实现的多选<!DOCTYPE /><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <t……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2713浏览 1880个赞
非常完善的Email正则表达式验证function _validateEmail( $email ){ var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[……继续阅读 » 水墨上仙 6年前 (2021-03-12) 1692浏览 379个赞
简单的JavaScript显示和隐藏元素// show or hide a selected element// if no state is given, the visibility is toggled// otherwise visibility is set to hidden or visible as selectedfunctio……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2581浏览 2365个赞
非常不错的js二进制时钟代码/******************************************************************************** Snarkles.Net Useless Binary Time (SNUBT)* * ThinkGeek's Binary LED Clock.……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2779浏览 235个赞
Javascript通过clientWidth,scrollWidth获取窗口宽度和高度<SCRIPT LANGUAGE="JavaScript"> var s = "网页可见区域宽 :"+ document.body.clientWidth; s += "\r\n网页可见区域高……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2128浏览 424个赞
用户选择表格数据时,点击某行,高亮显示某行<html><head><title></title><style type="text/css"> .trbg { background-color:Red; }</style> <s……继续阅读 » 水墨上仙 6年前 (2021-03-12) 1948浏览 1105个赞
定义了一个可以反复指定指定函数的类,功能类似于javascript中setTimeout# Simple version:import sys, timeclass RetryError(Exception): passdef retryloop(attempts, timeout): starttime = time.time(……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2772浏览 946个赞
JavaScript直接跳出下载的简单方法window.location = "../File/sharejs.zip";……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2779浏览 355个赞
php查询数据库显示小图,点击小图弹出大图<?php //Get all the images in the database (use a WHERE clause to limit what it finds) $sql = mysql_query("SELECT * FROM database_name"); //……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2388浏览 611个赞
这段代码演示了如何通过php建立一个简单的用户注册表单及提交程序<?php if(isset($_POST['submit'])){ # connect to the database here # search the database to see if the user name has been ……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2212浏览 1902个赞
js实现的单位轮流值班轮换表<script language="javascript"> var src="张三,李四,王五,赵六,钱七,孙八,曾久" var srcArray=src.split(",") var beginDate=new Date(20……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2453浏览 1570个赞
javascript通过正则表达式验证用户输入的金额是否正确<script type="text/javascript"> <!-- function MoneyCheck(){ var isNum = /^\d+(\.\d+)?$/; var money = docum……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3398浏览 1756个赞
通过记录开始时间和结束时间计算一段脚本的之行时间<?php //Create a variable for start time $time_start = microtime(true); // Place your PHP/HTML/JavaScript/CSS/Etc. Here //Create a variable for en……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2968浏览 2423个赞
JS如何访问navigator.* 变量<script type="text/javaScript"><!-- // dw() is just a alias for document.write()// to make the code shorter function dw(s){ docu……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2383浏览 2858个赞
JavaScript通过正则表达式处理url参数var url='www.baidu.com?a=123&b=456&c=789&e=dfsdfsdfsdfsdfsdfsdf&f=46545454545454785&g=e23232dsfvdfvdf'; /** * 格式化查询字符串(正则……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3340浏览 862个赞
通过JS打开图片另存为对话框,提示用户保存文件<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> New Document </title> <……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3104浏览 918个赞
JavaScript判断浏览器的类型var request = false;var btype=getinternet(); function getinternet() { if(navigator.useragent.indexof("msie")>0) { ret……继续阅读 » 水墨上仙 6年前 (2021-03-12) 1978浏览 2483个赞
node.js log模块日期格式化 在node.js开发过程中使用了npm install log默认下载的模块,日期时间很不符合习惯。[Tue Dec 25 2012 21……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2612浏览 499个赞
本代码首先通过head进行301转向,如果失败,则通过http-equiv=”Refresh”转向,如果不行再通过js进行转向,再不行直接在页面上输出链接地址让用户自己点击链接转向function safe_redirect($url, $exit=true) { // Only use the header red……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3245浏览 2274个赞
javascript获取当前鼠标的坐标位置<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ht……继续阅读 » 水墨上仙 6年前 (2021-03-12) 2320浏览 2440个赞
一个伦敦奥运会倒计时的JS代码,简单的修改一下就可以用作其它倒计时<SCRIPT LANGUAGE="JavaScript"> //作者:www.tongqiong.com<!-- var urodz= new Date("July 28,2012"); var s="伦敦奥……继续阅读 » 水墨上仙 6年前 (2021-03-12) 3194浏览 2378个赞