[html]functiongetUrlArg(seekArg){varurl=location.href;//先用正则把问号和井号之间的参数部分分离出来,如从http://www.jb51.net/testjs.htm?p=1&t=1&u=1#test中分出p=1&t=1&u=1if(reMatch=url.match(/\?([^#]+)#?/)){varquerystring=reMatch[1];//用正则按&或=拆分到数组里,args数组中依次是变量名和变量值,如p,1,t,2,u,24varargs=querystring.split(/&a...
http://www.jb51.net//article/16270.htm
replace()最简单的算是能力就是简单的字符替换。示例代码如下:[html]<scriptlanguage="javascript">varstrM="javascriptisagoodscriptlanguage";//在此我想将字母a替换成字母Aalert(strM.replace("a","A"));</script>[/html] 我想大家运行后可以看到结果,它只替换了首字母。但如果加上正则表达式结果就不一样了!呵呵,没错。replace()支持正则表达式,它可以按照正则表达式的规则匹配字符或字符串,然后给予替换![html]<scriptlangu...
http://www.jb51.net//article/16261.htm
[code]<tableid="PrintA"width="100%"border="1"cellspacing="0"cellpadding="0"bgcolor="#61FF13"><TRstyle="text-align:center;"><TD>单元格A</TD><TD>单元格A</TD><TD>单元格A</TD><TD>单元格A</TD></TR><TR><TDcolSpan=4style="text-align:center;">...
http://www.jb51.net//article/16254.htm
[code]<scriptlanguage=javascript>functionstoprefresh(){return"youwillloseanyunsavedcontent";}functionUnloadConfirm(){//页面离开后的事件alert('离开页面后的一些清理工作……');}</script><body><script>window.onbeforeunload=stoprefresh;//注册关闭前的事件window.onunload=UnloadConfirm;//注册关闭后的事件</script>&l...
http://www.jb51.net//article/16251.htm
[html]<inputtype="text"name="mytxt"value="12345678"/><br><inputtype="button"name="cmd1"onclick="mytxt2.value=mytxt.value.trim()"value="去两边的空格"/><inputtype="text"name="mytxt2"/><br><inputtype="button"name="cmd1"onclick="mytxt3.value=mytxt.value.ltrim()"value="去左边的空格"/...
http://www.jb51.net//article/16250.htm
javascript操作Select标记中options集合先来看看options集合的这几个方法:options.add(option)方法向集合里添加一项option对象;options.remove(index)方法移除options集合中的指定项;options(index)或options.item(index)可以通过索引获取options集合的指定项;javascript代码如下:varselectTag=null;//select标记varOPTONLENGTH=10;//每次填充option数varcolls=[];//对select标记options的引用window.on...
http://www.jb51.net//article/16240.htm
一Undefined类型只有一种值undefined以下三种情况typeof返回类型为undefined1.当变量未初始化时2.变量未定义时3.函数无明确返回值时(函数没有返回值时返回的都是undefined)undefined并不等同于未定义的值typeof并不真正区分是否是未定义看以下示例代码:varoTemp;alert(typeofoTemp);//outputs"undefined"alert(typeofoTemp2);//outputs"undefined"alert(oTemp2==undefined);//错误oTemp2未定义不能使用除了typeof之外的不能用来oTemp...
http://www.jb51.net//article/16238.htm
<divclass="form"><divclass="con"><ul><li>剩余字数的限制</li><li><textareacols="40"rows="8"id="text1"></textarea></li><li>剩余字符:<spanid="textleft"></span></li></ul></div></div><scriptlanguage="javascript">va...
http://www.jb51.net//article/16237.htm
关于js中的this关键字的文章已经不少了,我看过几篇,我写这篇文章的目的是从实例中分析出this的工作原理,希望对大家有所帮助。一、基本的:CodehighlightingproducedbyActiproCodeHighlighter(freeware)http://www.CodeHighlighter.com/-->function doSomething(){ alert(this.id);}alert(window.doSomething);//证明了doSomething是属于window的doSomething();//u...
http://www.jb51.net//article/16235.htm
[html]<html><head><title>javascript把15位身份证转成18</title><scriptlanguage="javascript">varv=newArray();varvs="10X98765432";varnewCardID="";functiononload(){document.getElementById("cardID").focus();}functioncheckCardID(cardID15){v.push(2,4,8,5,10,9,7,3,6,1,2,4,8,5,10,9,7);v...
http://www.jb51.net//article/16220.htm
本来觉得这个系统会很复杂,但把每个部分都分析清楚后,其实需要的技术并不高。不过当我把各个功能函数都整理好准备进行封装时,却发现要把程序封装不是那么容易,因为程序跟html的耦合度太高。然后我逐步把程序中操作html相关的部分分离出来,首先把简单的分离,接着是文件列表,然后是file控件,最后是一些提示性程序。经过几次尝试才把整个结构封装好。[html]<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><...
http://www.jb51.net//article/16219.htm
