Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么在modal.js中阻止检查div?_Javascript_Jquery_Twitter Bootstrap - Fatal编程技术网

Javascript 为什么在modal.js中阻止检查div?

Javascript 为什么在modal.js中阻止检查div?,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,嘿,伙计们刚刚浏览了modal.js的源代码,发现了以下几行代码 $target.one('show.bs.modal', function (showEvent) { if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown $target.one('hidden.bs.modal', function () { $th

嘿,伙计们刚刚浏览了modal.js的源代码,发现了以下几行代码

$target.one('show.bs.modal', function (showEvent) {
  if (showEvent.isDefaultPrevented())  return // only register focus restorer if modal will actually get shown
  $target.one('hidden.bs.modal', function () {
    $this.is(':visible') && $this.trigger('focus')
  })
})
$target实际上只是以下内容:

<div aria-hidden="false" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade in" style="display: block;">
有人能解释一下吗

我的难点也可以在git上找到:


谢谢

我看不出您认为
$target
DIV在哪里得到任何检查。实际上,
isDefaultPrevented
是一个标准,它指示用户是否试图截获show事件,从而影响默认事件处理。此函数是为事件对象调用的,而不是为该div上触发的事件名而调用的。$target

'show.bs.modal'

现在,您粘贴的代码的要点是:

如果另一段代码已经捕获了事件并在事件对象上调用了
preventDefault()
,那么,当执行这段代码时,它将使用
isDefaultPrevented
知道这一点,并返回而不执行任何操作


这样,您就可以防止该事件的默认行为,就像您可以防止
单击
事件的默认行为一样。

我的意思是,通常我看到在
类元素上应用了preventDefault,而不是
等。这并不意味着您不能触发事件(从而防止其他元素的默认事件行为)。
if (showEvent.isDefaultPrevented())  return