Jquery - 如何在页面加载时显示警告框?

时间:2016-11-29 12:07:23

标签: javascript jquery html

这里我使用jquery在onclick警告框的下面代码中使用,但我需要与onload函数相同的警告框。

   <link href="mdl.css" rel="stylesheet" type="text/css">
    <style>

.btn {
  display: inline-block;
  padding: 10px 20px;
  background-color: #5D9CEC;
  border-bottom: 3px solid #4A89DC;
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  margin:30px 10px;
}
</style
<div class="jquery-script-ads" style="margin:30px auto;">
</div>  <a class="btn" id="btn-2" data-type="confirm" data-fullscreen="false" data-overlayClick="true"> Confirm Dialog </a> </div>
<script src="http://code.jquery.com/jquery-1.12.4.min.js"></script> 
<script src="mdl.js"></script>

<script>

$('#btn-2').mdl({
  content:"Are You Sure To Delete This Entry?"

});


</script>

2 个答案:

答案 0 :(得分:0)

使用$.fn.trigger

在加载时触发点击事件
$('#btn-2').mdl({
  content:"Are You Sure To Delete This Entry?"
}).trigger('click')

答案 1 :(得分:-1)

(文档)$。就绪(    function(){

           alert(" content:"Are You Sure To Delete This Entry?");
        }
   );