我有一個JS代碼:如何在JavaScript中處理查詢字符串?
window.onload = function() {
document.getElementById("Button1").onclick = function() {
var t1 = document.getElementById("Text1").value;
var t2 = document.getElementById("Text2").value;
document.URL = 'myurl?t1=' + t1 + '&t2' + t2;
}
}
我在這裏將T1,T2作爲查詢param..now我的問題是可以說,我已經進入Textbox1的一些數據,但不能在TextBox2中,在這種情況下,URL我越來越是 'myurl?t1=' + value of textbox1 + '&t2' + This will be blank;
我想使它動態,即如果Textbox2中沒有值,那麼我不想追加queryparam t2,同樣也爲t1也..可能嗎?
如果其中一個值爲空,則不會中斷網址。並將document.URL改爲window.location或瀏覽器將不會打開該頁面(FF) – baloo 2010-06-02 08:31:30
yep.but僅僅是一個例子,而不是真正的應用程序。 – Wondering 2010-06-02 10:33:15