javascript转换canvas为image// Converts canvas to an imagefunction convertCanvasToImage(canvas) { var image = new Image(); image.src = canvas.toDataURL("image/png"); r……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2209浏览 1611个赞
通过jQuery提交表单并阻止表单的默认提交,通过e.preventDefault();可以阻止表单的默认提交相应,只执行submit里面的代码。<html><head><script type="text/javascript" src="/jquery/jquery.js"&……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3163浏览 1152个赞
JavaScript解决汉诺塔问题<script language="javascript"> var han=function (disc,src,aux,dst){ if(disc>0){ han(disc-1,src,dst,aux); document.writeln("move……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1554浏览 223个赞
基本的HTML5拖拽效果演示代码<!DOCTYPE HTML><html><head><style type="text/css">#div1 {width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;}&l……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2491浏览 930个赞
通过html5 canvas绘制简单的矩形<!DOCTYPE html><html><body><canvas id="myCanvas" width="200" height="100" style="border:1px solid……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2601浏览 2487个赞
通过html5的canvas绘制线条<!DOCTYPE html><html><body><canvas id="myCanvas" width="200" height="100" style="border:1px solid #d……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2423浏览 2403个赞
通过html5的canvas绘制圆形图案<!DOCTYPE html><html><body><canvas id="myCanvas" width="200" height="100" style="border:1px solid ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1687浏览 2733个赞
HTML5之特效之雨点效果代码<!DOCTYPE HTML> <html><head><script type="text/javascript" src="jquery-1.7.2.min.js"></script><script typ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1841浏览 813个赞
django通过ajax发起请求返回JSON格式的数据 这是后台处理的def checkemail(request): user = None if request.POST.has_key('email'): useremail……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2764浏览 336个赞
javascript table 隔行变色代码function changeTableColor(oddColor,evenColor){ var tables=document.getElementsByTagName('table'); for(var i=0;i<tables.length;i++){ var ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3121浏览 402个赞
基本的HTML5视频播放控制代码演示<!DOCTYPE html> <html> <body> <div style="text-align:center"> <button onclick="playPause()">Play/Pause&……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1960浏览 907个赞
javascript通过表格绘制颜色填充矩形<html> <head> <title> Javascript画矩形 </title> <script type="text/javascript"> //定义函数,传入设置参数,返回一个有背景颜色的表……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1760浏览 1062个赞
jquery.validate.js是jquery下的一个验证插件,功能比较强大,早就有所耳闻但是一只没有动手用过,现在在于能够研究一下了。 这里转载一篇前辈写的文章,在我自己的理解上修改了一下,仅作记录。 国内某大公司的代码<script type="text/……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2047浏览 1888个赞
JavaScript将一个整数数组先按照因子数量排序,再按照数字大小排序某笔试中的题,不得不承认这道题是个好题,考察了很多方面。js的数组操作,算法,逻辑能力,还有预防各种坑的能力……一共搞了大概有4小时,函数逐个用firebug测,无法想象在考场上大概不到1小时,还不能调试……能写对的绝对是个神。公司遇到这样的神,就算其他题都不写也应该收了。来源:http……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1827浏览 1723个赞
JavaScript中克隆对象function clone(obj) { // Handle the 3 simple types, and null or undefined if (null == obj || "object" != typeof obj) return obj; // Handle D……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3274浏览 786个赞
JavaScript中检查字符串是否为空的最简单方法if (strValue) { //do something}……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2654浏览 2174个赞
JavaScript对URL进行编码var myUrl = "http://example.com/index.html?param=1&anotherParam=2";var myOtherUrl = "http://example.com/index.html?url=" + encodeURICo……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2310浏览 1655个赞
JavaScript中16进制和10进制的相互转换var sHex=(255).toString(16);//ffvar iNum=parseInt("ff",16);//255……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3424浏览 2883个赞
107个JavaScript基本函数来源:http://blog.csdn.net/liuzx32/article/details/7770243 * 1.document.write(”");为 输出语句 * 2.JS中的注释为// * 3.传统的HTML文档顺序是:document->html->(head……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1857浏览 2471个赞
JavaScript的Base64编码代码片段var Base64 = {// private property_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",// public method for encoding……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1682浏览 873个赞
JavaScript字符与ASCII码之间的转换console.log("\n".charCodeAt(0));//10console.log(String.fromCharCode(65));//A……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3125浏览 2101个赞
自定义JavaScript中的endWith函数String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1;}; ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1831浏览 2234个赞
JavaScript添加和删除Class//Add Classdocument.getElementById("MyElement").className += " MyClass";//Remove Classdocument.getElementById("MyElement").c……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3296浏览 422个赞
javascript快速排序算法代码function qsort(a) { if (a.length == 0) return []; var left = []; var right = []; var pivot = a[0]; for (var i = a.length; --i;) { i……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2436浏览 2195个赞
javascript冒泡法排序算法演示代码<html><head><script type="text/javascript">// GLOBAL FUNCTIONArray.prototype.bubble_sort = function() { var i, j; va……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2272浏览 227个赞
JavaScript中的日期格式化Date.prototype.toString=function(format,loc){ var time={}; time.Year=this.getFullYear(); time.TYear=(""+time.Year).substr(2); time.Mon……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2324浏览 952个赞
这是一个非常简单形象的JS类使用范例,this的作用就是指向调用该方法的对象,比如这个例子,当调用new Person的时候,this就表示he这个对象,调用this.name 就等于 he.name。email前面为什么要使用一个下划线呢?因为js只有公共作用域,没有私用的属性和方法,所以开发者为了做区别,就用一个下划线表示这个属性或者方法是私有的,当然,……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1592浏览 1492个赞
这段代码演示了javascript中如何输入多行字符串var htmlSTring = "<div>\ This is a string.\</div>";……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3436浏览 2077个赞
JS选择textarea内的文本,全选<!------> <script type="text/javascript"> function select_field(id){ document.getElementById(id).focus(); docu……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2337浏览 2822个赞
将图片的src设置为blank.gif,真正的图片放到data-src<img src="blank.gif" class="lazy" data-src="/images/full-size.jpg" width="240" height="152&quo……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3245浏览 1060个赞
自定义个JS事件绑定函数,用这个函数绑定事件更方便<script type="text/javascript">/** * Attach an event handler on a given Node taking care of Browsers Differences * @param {Object} no……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2490浏览 2738个赞
这段代码是一个标准的JS版的MD5加密算法var MD5 = function (string) { function RotateLeft(lValue, iShiftBits) { return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits)……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1895浏览 2578个赞
JavaScript判断数组是否包含指定的元素,这段代码通过prototype定义了数组方法,这样就可以在任意数组调用contains方法/** * Array.prototype.[method name] allows you to define/overwrite an objects method * needle is the item ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2652浏览 2406个赞
JavaScript在文本框中默认显示图片背景,获得焦点后消失的代码效果演示:http://css-tricks.com/examples/InputWithBackgroundImage/ html代码<form name="searchform" id……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2419浏览 406个赞
JavaScript中setInterval定时器用法var int = setInterval("doSomething()", 5000 ); /* 5 seconds */var int = setInterval(doSomething, 5000 ); /* same thing, no quotes, no paren……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3804浏览 1807个赞
通过两端代码介绍JavaScript如何声明全局变量 在函数外定义全局变量var oneVariable;function setVariable(){ oneVariable = "Variable set from within a function!&qu……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2087浏览 1142个赞
本范例演示了JS如何获取当前url和url参数的获取function getUrlParm( name ){ var regexS = "[\\?&]"+name+"=([^&#]*)" ; var regex = new RegExp( regexS ) ; var tmpURL ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2032浏览 2506个赞
JavaScript得到url和url的各个部分Javascript可以获得当前页面地址,如:http://css-tricks.com/example/index.html通过window.location可以访问url的各个部分:window.location.protocol = ”http̶……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1659浏览 1984个赞
如果浏览器支持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) 1590浏览 801个赞
利用浏览器的缓存实现类似于浏览器的向前向后功能<input id="btnBack" type="button" value="Back" language="javascript" onclick="fnBack()" /><inp……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1684浏览 1081个赞
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) 3240浏览 858个赞
本范例演示了JS如何通过window.open函数打开一个新窗口,及其参数设置function open_window(url){ var wparams = 'toolbar=0,location=0,directories=0,status=0,menubar=0,'; wparams += ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3164浏览 1680个赞
这段代码用了一个非常巧妙的方法清空数组var myArray = ["one", "two", "three"];// console.log( myArray ) => ["one", "two", "three"]myA……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3010浏览 2193个赞
JavaScript获得url查询参数function getQueryVariable(variable){ var query = window.location.search.substring(1); var vars = query.split("&"); for (va……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1954浏览 2964个赞
只要给定Class,就能找到拥有这些class的元素function getElementsByClass(node,searchClass,tag) { var classElements = new Array(); var els = node.getElementsByTagName(tag); // use "*&q……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1883浏览 1005个赞