zoukankan      html  css  js  c++  java
  • 前端笔试题目小结--获取输入参数用户名;查询URL字符串参数

    编写一个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 }
  • 相关阅读:
    用sed删除空行
    烂泥:php5.6源码安装及php-fpm配置
    linux系统vsftpd登陆慢卡怎么办
    Linux Vsftpd 连接超时解决方法
    linux中shell截取字符串方法总结
    运算符
    数据类型
    is null 和=null的区别
    DML
    DDL
  • 原文地址:https://www.cnblogs.com/meggie523/p/4824738.html
Copyright © 2011-2022 走看看