Possible Duplicate:
How to break line in Javascript
我使用下面的 JavaScript 在客户网站的页面加载时显示弹出消息。我是一个真正的 js 新手,只能真正复制/粘贴我在网上找到的示例。需要知道如何设置弹出框的宽度。我希望文本跨越两行,而不仅仅是跨越页面的宽度。以下是 www.manageourwebsite.com.au 的显示示例
<body onload="WelcomeMSG()">
<script language="JavaScript">
<!--
function WelcomeMSG ()
{
alert("Our Retail shop front will be closed from Friday 21st December 2012 thru to Monday 21st January 2013. The Online store will be open 24/7 as usual with all online orders being processed as normal.")
}
-->
</script>
最佳答案
我会用一些 CSS(根据您自己的喜好设置样式)和一行 javascript
<style type="text/css">
#holiday-overlay{
position:fixed;
top:0; left:0; right:0; bottom:0;
background: rgba(255,255,255,0.7);
z-index:9999;
}
#holiday-message{
width:400px;
padding:30px;
background-color: black;
left:50%;
top:40%;
margin-left:-200px; /*half of width*/
border-radius:5px;
color:white;
position:relative;
}
#holiday-close{
paddding:5px;
position:absolute;
right:10px;
top:10px;
cursor:pointer;
font-weight:bold;
color:white;
}
</style>
<div id="holiday-overlay">
<div id="holiday-message">
<a onclick="var el = document.getElementById('holiday-overlay'); el.parentNode.removeChild(el)" id="holiday-close">×</a>
Our Retail shop front will be closed from Friday 21st December 2012 thru to Monday 21st January 2013.<br/>
The Online store will be open 24/7 as usual with all online orders being processed as normal.
</div>
</div>
关于javascript - 设置javascript弹出框的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13924550/