繁体   English   中英

按钮焦点在 JQuery 从页面后面的代码显示时对话框不起作用 - asp.net / c#

[英]Button focus on JQuery Dialog doesn't work when showing from code behind the page - asp.net / c#

我从后面的代码中调用了confirmDialog方法,该方法工作正常,但由于某些原因,焦点未设置在取消按钮上。 当我单击弹出窗口外的模态灰色区域时,设置焦点。

有没有办法在不点击页面的情况下将默认焦点设置在取消按钮上?

对话框打开后

在此处输入图像描述

鼠标点击灰色区域后;

在此处输入图像描述

这是代码;

 function confirmDialog() {

 $("#dialog-confirm").html("some message here");
 $("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
height: "auto",
width: "auto",
modal: true,
title: 'Warning!',
buttons: {
  "Ok": function() {
    $(this).dialog("close");
    return true;
  },
  Cancel: function() {
    $(this).dialog("close");
    return false;
  }
},
open: function() {
  $(this).siblings('.ui-dialog-buttonpane').find("button:contains('Cancel')").focus();
}
});

        return false;
}

您可以使用“nth-child(2)”来搜索模态中的第二个按钮:

$(this).parent().find('button:nth-child(2)').focus();

演示

暂无
暂无

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

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