gpt4 book ai didi

javascript - selectedIndexChanged 之后的 control.focus()

转载 作者:行者123 更新时间:2023-12-02 20:23:25 25 4
gpt4 key购买 nike

从下拉列表中选择项目后,我需要关注文本框。

我尝试过 control.focus() 和 setfocus()。

我尝试的最后一件事是使用以下方法在 SelectedIndexChanged 方法内设置 Set_Focus(dtbEffectiveDate.ClientID)。

Protected Sub Set_Focus(ByVal ControlName As String)
Dim strScript As String

strScript = "<script language=javascript> window.setTimeout(""" + ControlName + ".focus();"",0); </script>"
RegisterStartupScript("focus", strScript)
End Sub

我没有答案,所以任何帮助都会很棒。

最佳答案

您应该使用 document.getElementById(id) 在 javascript 中选择控件:

 document.getElementById('"+ControlName+"').focus();

类似于:

Protected Sub Set_Focus(ByVal ControlName As String)
Dim strScript As String

strScript = "<script language=javascript> window.setTimeout(document.getElementById('" + ControlName + "').focus();"",0); </script>"
RegisterStartupScript("focus", strScript)
End Sub

编辑:我不完全确定转义 ControlName 周围引号的正确 VB 语法。

关于javascript - selectedIndexChanged 之后的 control.focus(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5221935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com