转Y身
普通女子,胸无大志,只愿昨日可忆,未来可期,有山水可游,有奇事可闻,有朋友可交,有家人可依,文字之乐不改,童稚之心不灭,已是完满一生。

编写一个JavaScript函数getSuffix,用于获得输入参数的后缀名。如输入abc.txt,返回txt。

 1 str1 = "abc.txt";
 2 function getSuffix(str)
 3 {
 4    var index =str.indexOf(".");
 5    if(index !=-1)
 6    {
 7     str = str.substring(index+1);
 8    }
 9    else{
10    str = "not find";
11    }
12     return str;
13 }
14 
15 var temp =  getSuffix(str1);
16 console.log("%s",temp);

2、编写一个JavaScript函数,用以解析查询字符串,然后返回包含所有参数的一个对象。

 1 function getQueryStringArgs(){
 2     var qs = (location.search.length > 0 ? location.search.substring(1):"" ),
 3     args{},
 4     items = qs.length ? qs.split("&") : [],
 5     item = null,
 6     name = null,
 7     value = null,
 8     i=0;
 9     lenth = items.length;
10     for(i=0;i<len;i++)
11     {
12         item = items[i].spilt("=");
13         name = decodeURIComponent(item[0]);
14         value= decodeURIComponent(item[0]);
15         if(name.lenght){
16             args[name] = value;
17         }
18     }
19 }

 

posted on 2015-09-20 23:27  转Y身  阅读(294)  评论(0编辑  收藏  举报