简体   繁体   English

如何在模式弹出窗口中将焦点设置到DropDownList控件?

[英]How to Set Focus to a DropDownList control in a Modal Popup?

I have a bootstrap modal popup which has the first first a dropdownlist and I want the user to be able to table through the fields without having to use the mouse to set the focus in the modal popup. 我有一个引导模式弹出窗口,该窗口具有第一个第一个下拉列表,我希望用户能够在不使用鼠标设置模式弹出窗口中设置焦点的情况下浏览字段。 I can do this fine if the first field is a text box, but when it is a dropdownlist I can't get this to focus using the ddl_list.Focus() command. 如果第一个字段是文本框,我可以做到这一点,但是当它是一个下拉列表时,我无法使用ddl_list.Focus()命令使它集中显示。

This was solved after some further searching. 经过进一步搜索后,此问题得以解决。 Simply add the following javascript to the aspx file. 只需将以下javascript添加到aspx文件。 This sets focus to the field field in a bootstrap popup modal. 这会将焦点设置为引导弹出窗口模式中的field字段。

<script type="text/javascript">
    $('body').on('shown.bs.modal', function (e) {
        var ele = $(e.target).find('input[type=text],textarea,select').filter(':visible:first'); // find the first input on the bs modal
        if (ele) {ele.focus();} // if we found one then set focus.
    })      
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM