我正在尝试使用javascript / jquery关注页面加载时的ASP下拉列表。我可以通过使用DDL_Department.Focus()
方法的代码来完成它。但我正在尝试使用javascript / jquery。
我尝试了三种方法,但没有成功。请参阅代码。
<asp:Content ID="UserContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<div class="form-group">
<label class="col-md-2 control-label">Department</label>
<div class="col-md-4">
<asp:DropDownList ID="DDL_Department" class="form-control input_text" runat="server">
<asp:ListItem Text="--Select Department--" Value="" />
</asp:DropDownList>
</div>
</div>
<script>
//first approach
//not successful
$(function () {
$('# <%= DDL_Department.ClientID %>').focus();
});
//////
//second approach
//not successful
$(function () {
$('#DDL_Department').focus();
});
//////
//third approach
//not successful
$(function () {
$("[id$=DDL_Department]").focus();
});
//////
</script>
</asp:Content>
答案 0 :(得分:0)
您可以尝试更改:
$(function () {
$('# <%= DDL_Department.ClientID %>').focus();
});
为:
$(function () {
$('#<%= DDL_Department.ClientID %>').focus();
});
(去除英镑字符后的空白区域)
答案 1 :(得分:-1)
你可以使用
$('#DDL_Department').focus();
没有别的。