为什么写在window.onload=function(){}里面的函数在执行的时候显示未定义
<scripttype="text/javascript">$(document).ready(function(){alert("ss");$('a.btn-ok,#d...
<script type="text/javascript">
$(document).ready(function(){
alert("ss");
$('a.btn-ok, #dialog-overlay, #dialog-box').click(function () {
$('#dialog-overlay, #dialog-box').hide();
return false;
});
$(window).resize(function () {
//only do it if the dialog box is not hidden
if (!$('#dialog-box').is(':hidden')) popup();
});
function popup(message) {
var maskHeight = $(document).height();
var maskWidth = $(window).width();
var dialogTop = (maskHeight/3) - ($('#dialog-box').height());
var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);
$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
$('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();
$('#dialog-message').html(message);
}
});
</script>
</head>
<body onload="popup('<p>You can pass html code to it as well:</p>">
<a href="javascript:popup('Lorem ipsum dolor sit amet')">Popup!</a>
<div id="dialog-overlay"></div>
<div id="dialog-box">
<div class="dialog-message"></div>
<a href="#" class="button"></a>
</div>
</body>
</html>
我把函数popup定义在window.onload里面的时候出现错误说popup为定义 就是 popup not defined
这是为什么? 展开
$(document).ready(function(){
alert("ss");
$('a.btn-ok, #dialog-overlay, #dialog-box').click(function () {
$('#dialog-overlay, #dialog-box').hide();
return false;
});
$(window).resize(function () {
//only do it if the dialog box is not hidden
if (!$('#dialog-box').is(':hidden')) popup();
});
function popup(message) {
var maskHeight = $(document).height();
var maskWidth = $(window).width();
var dialogTop = (maskHeight/3) - ($('#dialog-box').height());
var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);
$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
$('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();
$('#dialog-message').html(message);
}
});
</script>
</head>
<body onload="popup('<p>You can pass html code to it as well:</p>">
<a href="javascript:popup('Lorem ipsum dolor sit amet')">Popup!</a>
<div id="dialog-overlay"></div>
<div id="dialog-box">
<div class="dialog-message"></div>
<a href="#" class="button"></a>
</div>
</body>
</html>
我把函数popup定义在window.onload里面的时候出现错误说popup为定义 就是 popup not defined
这是为什么? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询