JavaScript中setInterval定时器用法var int = setInterval("doSomething()", 5000 ); /* 5 seconds */var int = setInterval(doSomething, 5000 ); /* same thing, no quotes, no paren……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3440浏览 270个赞
通过两端代码介绍JavaScript如何声明全局变量 在函数外定义全局变量var oneVariable;function setVariable(){ oneVariable = "Variable set from within a function!&qu……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2883浏览 1389个赞
本范例演示了JS如何获取当前url和url参数的获取function getUrlParm( name ){ var regexS = "[\\?&]"+name+"=([^&#]*)" ; var regex = new RegExp( regexS ) ; var tmpURL ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3082浏览 1977个赞
JavaScript得到url和url的各个部分Javascript可以获得当前页面地址,如:http://css-tricks.com/example/index.html通过window.location可以访问url的各个部分:window.location.protocol = ”http̶……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3163浏览 607个赞
如果浏览器支持JS将会输出welcome ,you have javascript on,否则输出JavaScript is off. Please enable to view full site.<script type="text/javascript"> document.write("Welco……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2426浏览 1809个赞
利用浏览器的缓存实现类似于浏览器的向前向后功能<input id="btnBack" type="button" value="Back" language="javascript" onclick="fnBack()" /><inp……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2516浏览 1174个赞
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;……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1603浏览 1786个赞
本范例演示了JS如何通过window.open函数打开一个新窗口,及其参数设置function open_window(url){ var wparams = 'toolbar=0,location=0,directories=0,status=0,menubar=0,'; wparams += ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2126浏览 2068个赞
这段代码用了一个非常巧妙的方法清空数组var myArray = ["one", "two", "three"];// console.log( myArray ) => ["one", "two", "three"]myA……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2248浏览 1300个赞
JavaScript获得url查询参数function getQueryVariable(variable){ var query = window.location.search.substring(1); var vars = query.split("&"); for (va……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2215浏览 1213个赞
只要给定Class,就能找到拥有这些class的元素function getElementsByClass(node,searchClass,tag) { var classElements = new Array(); var els = node.getElementsByTagName(tag); // use "*&q……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1961浏览 2316个赞
JS获取页面的宽度和高度,窗口的宽度和高度,返回一个数组//// getPageSize()// Returns array with page width, height and window width, height// Core code from - quirksmode.org// Edit for Firefox by pHaez……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2667浏览 1580个赞
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……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2747浏览 1327个赞
这段js代码通过每天在不同时段自动更换网页调用的样式表,实现更换皮肤的功能。<script type="text/JavaScript"><!--function getStylesheet() { var currentTime = new Date().getHours(); if ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2116浏览 2982个赞
JavaScript检测IE浏览器版本的代码<script type="text/javascript">if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x; var ieversion=new Number(RegExp.$……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2976浏览 1088个赞
JavaScript随机从数组读取一项数据function write_quote() { var quotes = [ 'no animals were harmed while making this page', 'made in ulm', ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1480浏览 239个赞
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 = '……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1610浏览 285个赞
HTML5的搜索框写法,在HTML4时代,弄个搜索框要实现一些基本功能都需要JS的辅助,HTML5做了很多HTML4应该做但是没有做的事情。<form><p><label>Search:<input name=search autofocus /></label></p><……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3344浏览 1802个赞
javascript读取java变量import java.awt.*; import java.applet.*; public class InJava3 extends Applet{ public int iJava = 123; public String sJava = "String from ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1915浏览 277个赞
JS输出一个随机数函数function RandomNumber(){ return Math.ceil(Math.random() * 85);}……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3763浏览 1462个赞
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); } ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1647浏览 215个赞
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……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2829浏览 275个赞
HTML5轻松实现拖拽效果的演示范例<!DOCTYPE HTML><html><head><style type="text/css">#div1, #div2{float:left; width:100px; height:35px; margin:10px;padding……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3253浏览 2975个赞
使用html的标记返回顶部,需要在顶部添加一个标记,本代码靠js实现,无需顶部标记<!------> <script type="text/javascript"> function init(){ document.getElementById('gtop').oncli……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3096浏览 293个赞
一个计算多个参数总和的JS函数,可以提供任意多个参数,计算出总和var sum = function() { var args = toArray.apply(null, arguments); // alert(args.length); if (args.length == 1) return args[……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3364浏览 2639个赞
纯JavaScript实现的淡入淡出效果,无需jQuery一类的框架,非常不错。function opacity(id, opacStart, opacEnd, millisec) { //speed for each frame var speed = Math.round(millisec / 100); var timer = 0; //……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1882浏览 1674个赞
javascript输出格式化后的数组String.prototype.print_f = function() { var formatted = this; for (var i = 0; i < arguments.length; i++) { var regexp = new RegExp('\\……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3133浏览 2631个赞
这段代码可以在客户端检测常用的操作系统类型//OS DETECTION...var OSName="Unknown OS";if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";if (navigator.appVer……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1818浏览 2304个赞
本js代码通过对js对象进行各方面的比较来判断两个对象是否相等Object.equals = function( x, y ) { // If both x and y are null or undefined and exactly the same if ( x === y ) { retu……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1908浏览 2803个赞
JS通过navigator对象检测浏览器的类型,这个函数可以直接用在你的项目中,非常方便function whichBrs() { var agt=navigator.userAgent.toLowerCase(); if (agt.indexOf("opera") != -1) return 'Opera'……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2882浏览 2119个赞
jQuery实现的多选<!DOCTYPE /><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <t……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2270浏览 714个赞
非常完善的Email正则表达式验证function _validateEmail( $email ){ var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2951浏览 637个赞
简单的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……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1907浏览 2849个赞
非常不错的js二进制时钟代码/******************************************************************************** Snarkles.Net Useless Binary Time (SNUBT)* * ThinkGeek's Binary LED Clock.……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2847浏览 2727个赞
Javascript通过clientWidth,scrollWidth获取窗口宽度和高度<SCRIPT LANGUAGE="JavaScript"> var s = "网页可见区域宽 :"+ document.body.clientWidth; s += "\r\n网页可见区域高……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2284浏览 1321个赞
用户选择表格数据时,点击某行,高亮显示某行<html><head><title></title><style type="text/css"> .trbg { background-color:Red; }</style> <s……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3231浏览 817个赞
定义了一个可以反复指定指定函数的类,功能类似于javascript中setTimeout# Simple version:import sys, timeclass RetryError(Exception): passdef retryloop(attempts, timeout): starttime = time.time(……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2558浏览 1052个赞
JavaScript直接跳出下载的简单方法window.location = "../File/sharejs.zip";……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2918浏览 2909个赞
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"); //……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2039浏览 1773个赞
这段代码演示了如何通过php建立一个简单的用户注册表单及提交程序<?php if(isset($_POST['submit'])){ # connect to the database here # search the database to see if the user name has been ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2755浏览 856个赞
js实现的单位轮流值班轮换表<script language="javascript"> var src="张三,李四,王五,赵六,钱七,孙八,曾久" var srcArray=src.split(",") var beginDate=new Date(20……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2021浏览 193个赞
javascript通过正则表达式验证用户输入的金额是否正确<script type="text/javascript"> <!-- function MoneyCheck(){ var isNum = /^\d+(\.\d+)?$/; var money = docum……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1924浏览 2178个赞
通过记录开始时间和结束时间计算一段脚本的之行时间<?php //Create a variable for start time $time_start = microtime(true); // Place your PHP/HTML/JavaScript/CSS/Etc. Here //Create a variable for en……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3099浏览 1464个赞
JS如何访问navigator.* 变量<script type="text/javaScript"><!-- // dw() is just a alias for document.write()// to make the code shorter function dw(s){ docu……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1733浏览 2721个赞
JavaScript通过正则表达式处理url参数var url='www.baidu.com?a=123&b=456&c=789&e=dfsdfsdfsdfsdfsdfsdf&f=46545454545454785&g=e23232dsfvdfvdf'; /** * 格式化查询字符串(正则……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1967浏览 1118个赞