我想在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