如何从 javascript 写到 JQuery

How to write this from javascript to JQuery

简单的问题我需要jquery中的javascript这几行。 当我 select 在它外面时,只是试图关闭它。

谢谢。

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

我假设正在点击模式 "myModal" ... 所以 ...

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

假设您将点击 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');
});