何必呢?你只是假设一个默认的,所以当你处理你的网页,并期待它只是设置为默认的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