将参数添加到url

时间:2015-07-06 07:24:54

标签: javascript

我尝试测试函数s.Util.getQueryParam。

我的网址格式为

http://project1/project1.html

我想在之后在网址中添加一些参数,以便有类似这种格式的内容

http://project1/project1.html/?id=03

我尝试使用此example

// www.mysite.com/my_app.html?Use_Id=abc 

var GET = {};
var query = window.location.search.substring(1).split("&");
for (var i = 0, max = query.length; i < max; i++)
{
    if (query[i] === "") // check for trailing & with no param
        continue;

    var param = query[i].split("=");
    GET[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || "");
}

我尝试添加Get this id = 03但是当我刷新浏览器时它无法正常工作我看不到参数。是否有可能帮助我如何以正确的方式运行它?

1 个答案:

答案 0 :(得分:3)

您可以修改1以添加查询参数。这将导致浏览器加载新URL(页面将被刷新)。

示例:var dataset = []; // The arrays xpoints and ypoints are populated dynamically // with hundreds of thousands of points var xpoints = chartData["xdata"]; var ypoints = chartData["ydata"]; var area1; var svg = dimple.newSvg("#" + mychart, 700, 600); var x, y; for (var i = 0; i < xpoints.length; i++) dataset.push({ x : xpoints[i], y1 : parseFloat(ypoints[i]) }); var myChart = new dimple.chart(svg, dataset); myChart.setBounds(75, 30, 480, 330); y = myChart.addMeasureAxis("y", "y1"); x = myChart.addCategoryAxis("x", "x"); area1 = myChart.addSeries("First", dimple.plot.area, [ x, y ]); var l = myChart.addLegend(65, 10, 510, 20, "right"); myChart.draw(1500);