当前位置: 代码迷 >> JavaScript >> 闲来干的一些js尝试
  详细解决方案

闲来干的一些js尝试

热度:108   发布时间:2012-10-30 16:13:36.0
闲来做的一些js尝试

??? /*获取url参数值*/

??? var url="http://www.i170.com/test.do?a=123&b=456&c=789&url=http://www.i170.com/test.do?a=123&b=456&c=789";
??? function getQueryStr(str){
??????? var rs = new RegExp("(^|)"+str+"=([^\&]*)(\&|$)","gi").exec(url);
??????? return rs;
??? }
??? alert(getQueryStr("b"));

??? /*扩展String类,使之具有去除左右空白的功能*/
??? String.prototype.LTrim=function(){
??? ??? var space=new String(' ');
??? ??? var s=new String(this);
??? ??? if(space.indexOf(s.charAt(0))!=-1){
??? ??? ??? var j=0,i=s.length;
??? ??? ??? while(j<i&&space.indexOf(s.charAt(j))!=-1){
??? ??? ??? ??? j++;
??? ??? ??? }
??? ??? ??? s=s.substring(j,i);
??? ??? }
??? ??? return s;
??? };
??? String.prototype.RTrim=function(){
??? ??? var space=new String(' ');
??? ??? var s=new String(this);
??? ??? var j=s.length-1;
??? ??? if(space.indexOf(s.charAt(j))!=-1){
??? ??? ??? while(j>=0&&space.indexOf(s.charAt(j))!=-1){
??? ??? ??? ??? j--;
??? ??? ??? }
??? ??? ??? s=s.substring(0,j+1);
??? ??? }
??? ??? return s;
??? };
??? String.prototype.Trim=function(){
??? ??? var s=new String(this);
??? ??? return s.LTrim().RTrim();
??? };
??? alert('['+('???? a??? b???? c????? ').Trim()+']');

  相关解决方案