如何将其从javascript写入JQuery
简单的问题我需要jquery中的这几行javascript。 当我选择一个模式之外的时候,我只是试图关闭它 多谢各位如何将其从javascript写入JQuery,javascript,jquery,window,simplemodal,Javascript,Jquery,Window,Simplemodal,简单的问题我需要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"; } } 我假设模态被点击“myModal”。
// 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的modal
$('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');
});
当您选择“在it之外”时,您需要提供更多信息吗?您显示的代码似乎与此相反,即当您单击它时关闭。这很有效,谢谢!