我想在vb.net網頁上使用scrollintoview jQuery plugin,不幸的是,在jQuery上相當新的我遇到了問題。VB.net和jQuery scrollintoview插件 - 滾動到一個特定的「輸入」元素
我有一個很長的表單,提交按鈕在底部。驗證在用戶點擊提交後的代碼中完成。
在我的validate()子, 我把控件的ID錯誤(比如txtFirstName)在一個變量ControlInErrorID
controlInErrorID = txtFirstName.ClientID
然後我試圖滾動到最後一個控制錯誤使用腳本經理:
If controlInErrorID <> String.Empty Then
Dim csname1 As [String] = "ShowControlInErrorScript"
Dim cstype As Type = Me.[GetType]()
' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Check to see if the startup script is already registered.
If Not cs.IsStartupScriptRegistered(cstype, csname1) Then
Dim cstext1 As New StringBuilder()
cstext1.Append("<script type=text/javascript>")
cstext1.Append("$(document).ready(function() {")
cstext1.Append(" $(""#" + controlInErrorID + """).scrollintoview({")
cstext1.Append(" duration: 5000,")
cstext1.Append(" direction: ""vertical"",")
cstext1.Append(" complete: function() {")
'cstext1.Append("// highlight the element so user's focus gets where it needs to be")
cstext1.Append(" }")
cstext1.Append("});})")
cstext1.Append("</script>")
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString())
End If
End If
麻煩的是,當運行這個,我沒有錯誤,但沒有任何反應。 有什麼想法嗎?
非常感謝!
當您遇到錯誤時,您只註冊腳本,不執行腳本。我認爲你需要重新加載頁面才能執行javascript代碼。 – 2012-02-21 20:56:13