何必呢?你只是假設一個默認的,所以當你處理你的網頁,並期待它只是設置爲默認的p
查詢字符串值,如果有不匹配的值...
Dim p
p = Request.QueryString("p")
If "" & p = "" Then p = 1
無需任何頁面重新加載。
藉此階段進一步我傾向於使用這樣的功能...
'GetPostData
' Obtains the specified data item from the previous form get or post.
'Usage:
' thisData = GetPostData("itemName", "Alternaitve Value")
'Parameters:
' dataItem (string) - The data item name that is required.
' nullVal (variant) - The alternative value if the field is empty.
'Description:
' This function will obtain the form data irrespective of type (i.e. whether it's a post or a get).
'Revision info:
' v0.2 - Function has been renamed to avoid confusion.
' v0.1.2 - Inherent bug caused empty values not to be recognised.
' v0.1.1 - Converted the dataItem to a string just in case.
function GetPostData(ByVal dataItem, ByVal nullVal)
dim rV
'Check the form object to see if it contains any data...
if request.Form("" & dataItem) = "" then
if request.QueryString("" & dataItem)="" then
rV = CStr(nullVal)
else
rV = request.QueryString("" & dataItem)
end if
else
rV = request.Form("" & dataItem)
end if
'Return the value...
GetPostData = rV
end function
...讓我的代碼整潔。如果發佈的數據丟失,該函數僅返回默認值。請注意,此函數在返回默認值之前將實際檢查QueryString和Form數據。
這個問題被標記爲vbscript,但你已經給了一個JavaScript的答案。正如在另一個解決方案中指出的那樣,最初的問題是最大化混合兩者。 – Dijkgraaf
這很清楚_不是JavaScript的答案_('如果是VB,而不是JS)。雖然這個答案可能是正確和有用的,但是如果你包含一些解釋並解釋它是如何幫助解決問題的,那麼這是首選。如果存在導致其停止工作並且用戶需要了解其曾經工作的變化(可能不相關),這在未來變得特別有用。 –
它看起來像VBS,但'window.location'表明它是客戶端代碼。客戶端VBS是獨立於ASP的東西(只有Internet Explorer支持) – John