您的位置:首页 > Web前端 > HTML

关于HTML页面接受请求参数

2016-10-27 09:27 218 查看
第一种:

var a = getArgs()['参数名'];

function getArgs() { 

    var args = {};

        var query = location.search.substring(1);

         // Get query string

    var pairs = query.split("&"); 

                    // Break at ampersand

     for(var i = 0; i < pairs.length; i++) {

            var pos = pairs[i].indexOf('=');

             // Look for "name=value"

            if (pos == -1) continue;

                    // If not found, skip

                var argname = pairs[i].substring(0,pos);// Extract the name

                var value = pairs[i].substring(pos+1);// Extract the value

                value = decodeURIComponent(value);// Decode it, if needed

                args[argname] = value;

                        // Store as a property

        }

    return args;// Return the object 

 }

第二种:

1.html

2.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐