我想参数添加到URL,对于我有2个文本框和一个按钮,我想不出我在哪里卡住,无法添加参数以URL
这里是我的代码:
无法添加参数,URL
HTML:
Param Name: <input id="tbAddParam" type="text" /><br>
Param Value: <input id="tbAddParamValue" type="text" /><br>
<input onclick="javascript:AddParamter();" value="Add" type="button" />
的JavaScript:
function AddParamter() {
var new_url = AddUrlParameter(window.location.href, document.getElementById('tbAddParam').value, document.getElementById('tbAddParamValue').value);
window.location.href = new_url;
}
function AddUrlParameter(a, b, c) {
if (b.trim() == "") {
alert("Parameter name should not be empty.");
return a;
}
if (c.trim() == "") {
alert("Parameter value should not be empty.");
return a;
}
if (a.indexOf("?") == -1) {
return a + "?" + b + "=" + c;
}
var d = a.split("?");
if (d.length >= 2) {
if (d[1].trim() == "") {
return d[0] + "?" + b + "=" + c;
}
var e = d[1].split(/[&;]/g);
for (var f = 0; f < e.length; f++) {
var g = e[f]; var h = g.split("=");
if (h.length >= 2) {
if (h[0] == b) {
alert("Url Parameter with provided name already exists! Try Updating that Url Parameter.");
return a;
}
}
}
return a + "&" + b + "=" + c;
}
}
哪些具体问题? – 2013-02-25 06:17:43
你有什么错误(如果有的话)?这不起作用的方式? – Keppil 2013-02-25 06:17:53
这是一个JavaScript问题,不解决Java,HTML或JSP问题= \ – 2013-02-25 06:18:24