【问题标题】:How to write this from javascript to JQuery [closed]如何将这个从 javascript 写到 JQuery [关闭]
【发布时间】:2016-02-01 03:51:20
【问题描述】:

简单的问题,我需要 jquery 中的这几行 javascript。 当我在它之外选择时试图关闭它。

谢谢。

 // When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
 if (event.target == myModal) {
    myModal.style.display = "none";
}
}

【问题讨论】:

  • 您需要提供更多信息
  • 什么时候选择“外面”?您显示的代码似乎与此相反,即单击它时关闭。

标签: javascript jquery window simplemodal


【解决方案1】:

我假设模态被点击“myModal”......所以......

$("#myModal").on("click",function() {
    $(this).hide();
});

【讨论】:

  • 成功了,谢谢!
【解决方案2】:

假设您将点击 body 并检查目标是否是带有 Id myModal 的模态

$('body').on('click',function(event){
  var getTargetId = event.target.id;
  if(getTargetId== myModal){
     $(this).attr('display', 'none')
   }
})

假设您将点击 id 为 myModal 的模态

$("#myModal").on("click",function() {
    $(this).attr('display', 'none');
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    相关资源
    最近更新 更多