如何在jQuery.blur()/ focusout()上使用jQuery(":focus")选择器?

时间:2016-04-26 15:34:29

标签: javascript jquery

正如您在下面的示例中所看到的,我无法获得具有焦点的元素。 对我来说奇怪的是,div 在浏览器标签切换上失去了重点。回到此浏览器标签

时,重新获得关注

我确实尝试过一些像focusout / focusin这样的事情,我会用下面几分钟尝试的例子来更新这篇文章



$("div").attr("contentEditable", true);
$(window)
  .on("focus", function() {
    console.log("document is on!");
  })
  .on("blur", function() {
    console.log("document is off!");
    console.log($("div:focus"));
    $(":focus").blur();
    $(":focus").focusout();
  });
$("div")
  .on("focus", function() {
    console.log("div is on!");
  })
  .on("blur", function() {
    console.log("div is off!");
  });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>span</div>
&#13;
&#13;
&#13;

向窗口焦点事件FAILED 添加了模糊/焦点

&#13;
&#13;
$("div").attr("contentEditable", true);
$(window)
  .on("focus", function() {
    console.log("document is on!");
    console.log($("div:focus"));
    $(":focus").blur();
    $(":focus").focusout();
  })
  .on("blur", function() {
    console.log("document is off!");

  });
$("div")
  .on("focus", function() {
    console.log("div is on!");
  })
  .on("blur", function() {
    console.log("div is off!");
  });

/*added blur/focusout on focus event*/
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>span</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案