警报消息很难使用,因为它会冻结浏览器,直到您单击它关闭,这需要您移动鼠标,然后。再加上blur,当你离开元素时会触发(当你点击警告框时会触发…),这是一个糟糕的组合。
建议:创建一个简单的DIV
position:fixed; top:0; left:25%;
并将您的消息插入到该div的HTML中,等待用户单击页面上的任意位置以关闭它。用这个来代替提醒功能,你会更快乐。
$('#mybutt').click(function(){
var mymsg = "<i>Here is a sample message. Click on <b>me</b> to close.</i>";
$('#msg').html(mymsg);
$('#msg').show();
});
$('#nuther').click(function(){
var mymsg = "<div id='nuth'>Here is another message. Click on <b>me</b> to close.</div>";
$('#msg').html(mymsg);
$('#msg').show();
});
$('#msg').click(function(){
$('#msg').hide();
});
#msg{position:fixed;top:10%;left:25%;padding:10px;text-align:center;}
#msg{font-size:1.3rem;background:bisque;z-index:2;display:none;}
#nuth{color:dodgerblue;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="msg"></div>
<button id="mybutt">Click me</button>
<button id="nuther">Nuther button</button>