0

当我在甜蜜警报上使用输入字段时,我遇到了一个奇怪的错误,我的输入字段内不能有光标,这是一个 jsfiddle。

https://jsfiddle.net/gvzwu5st/

如果我包括

showConfirmButton: false

然后它工作正常这里是小提琴

https://jsfiddle.net/16L4sddt/

4

1 回答 1

0

When you have showConfirmButton: true, the openModal() function (line 653) gives focus to the confirm button (line 662):

$okButton.focus();

When you try to click in the input field, the handleOnBlur() function (line 396) is called because the confirm button loses the focus. The functions defines the $targetElement variable which refers to the confirm button (line 397). Skipping some lines... the function will loop through each button of the modal to check if it is the element that got the focus. In your case, the target element is the input field, so it is not any of the buttons. The variable btnIndex keeps the value -1. Lines 413-416:

if (btnIndex === -1) {
  // Something in the dom, but not a visible button. Focus back on the button.
  $targetElement.focus();
}

So the confirm button ($targetElement) is given back the focus, which prevents the input field from ever receiving it.

于 2015-12-30T16:03:51.683 回答