<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">cssText 的本质就是设置 HTML 元素的 style 属性值。</span>
<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">在某些浏览器中(比如 Chrome),你给他赋什么值,它就返回什么值。在 IE 中则比较痛苦,它会格式化输出、会把属性大写、会改变属性顺序、会去掉最后一个分号,比如:</span>
</span>
<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"></span><div id="code42626" class="codebody" style="margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">document.getElementById("d1").style.cssText = "color:red; font-size:13px;";</div><div id="code42626" class="codebody" style="margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><br style="margin: 0px; padding: 0px;" />alert(document.getElementById("d1").style.cssText);</div><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"> </p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">在 IE 中值为:FONT-SIZE: 13px; COLOR: red。</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">
</p>
<img src="https://img-blog.csdn.net/20160914214809420?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>dialog</title>
</head>
<body>
<button id="id" οnclick="createMessTipWin(param)">按钮</button>
<div id="myList"></div>
<span style="white-space:pre"> </span><script type="text/javascript">
/**
<span style="white-space:pre"> </span>* by nacky.long
<span style="white-space:pre"> </span>* 创建自定义弹窗
<span style="white-space:pre"> </span>* @param param
<span style="white-space:pre"> </span>* 参数结构:
<span style="white-space:pre"> </span>param = {
title:'提示',
tips:"没有任何提示信息!",
btnOk:'是',
btnNo:'否',
funcOk:function () {
},
funcNo:function () {
}
}
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>function createMessTipWin(param) {
<span style="white-space:pre"> </span>if (arguments.length==0) {
<span style="white-space:pre"> </span> param = {
<span style="white-space:pre"> </span>title:'友情提示',
<span style="white-space:pre"> </span>tips:"没有任何提示信息!",
<span style="white-space:pre"> </span> btnOk:'是',
<span style="white-space:pre"> </span>btnNo:'否',
<span style="white-space:pre"> </span>funcOk:function () {
<span style="white-space:pre"> </span> },
<span style="white-space:pre"> </span>funcNo:function () {
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>var tipWinObj = document.createElement("div");
<span style="white-space:pre"> </span> tipWinObj.style.cssText = "position:fixed;z-index:9999;width:300px; height:auto; overflow:hidden;background-color:white; border:solid 1px #231234;padding-bottom:10px;";
<span style="white-space:pre"> </span>tipWinObj.style.top = '30%';
<span style="white-space:pre"> </span>tipWinObj.style.left = '40%';
<span style="white-space:pre"> </span> var topDiv = document.createElement("div");
<span style="white-space:pre"> </span>topDiv.style.cssText = "height;30px; line-height:30px; font-size:14px;background-color:#231234;color:white;";
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span> var titDiv = document.createElement("div");
<span style="white-space:pre"> </span>titDiv.style.cssText = "float:left; width:80%;margin-left:5px;";
<span style="white-space:pre"> </span>titDiv.innerHTML = param.title;
<span style="white-space:pre"> </span>var cross = document.createElement("div");
<span style="white-space:pre"> </span>cross.style.cssText = "float:right; cursor:pointer;margin-right:5px;";
<span style="white-space:pre"> </span>cross.innerHTML = 'X';
<span style="white-space:pre"> </span>var clearDiv = document.createElement("div");
<span style="white-space:pre"> </span>clearDiv.style.cssText = "clear:both";
<span style="white-space:pre"> </span>var contentDiv = document.createElement("div");
<span style="white-space:pre"> </span>contentDiv.style.cssText = "height:auto; overflow:hidden; line-height:24px;padding:0px 10px 10px;text-align:center;margin-top:10px;";
<span style="white-space:pre"> </span>contentDiv.innerHTML = param.tips;
<span style="white-space:pre"> </span>var okBtn = document.createElement("button");
<span style="white-space:pre"> </span>okBtn.style.cssText = "float:right; width:50px; margin-right:10px;cursor:pointer ";
<span style="white-space:pre"> </span>okBtn.innerHTML = param.btnOk;
<span style="white-space:pre"> </span>var noBtn = document.createElement("button");
<span style="white-space:pre"> </span>noBtn.style.cssText = "float:right; width:50px;cursor:pointer;margin-right: 10px;";
<span style="white-space:pre"> </span>noBtn.innerHTML = param.btnNo;
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>//获取当前页面的第一个body节点对象,
<span style="white-space:pre"> </span>var body = document.getElementById("myList");
<span style="white-space:pre"> </span>body.appendChild(tipWinObj);
<span style="white-space:pre"> </span>tipWinObj.appendChild(topDiv);
<span style="white-space:pre"> </span>tipWinObj.appendChild(contentDiv);
<span style="white-space:pre"> </span>tipWinObj.appendChild(noBtn);
<span style="white-space:pre"> </span>tipWinObj.appendChild(okBtn);
<span style="white-space:pre"> </span>topDiv.appendChild(titDiv);
<span style="white-space:pre"> </span>topDiv.appendChild(cross);
<span style="white-space:pre"> </span>topDiv.appendChild(clearDiv);
<span style="white-space:pre"> </span>//鎖屏DIV
<span style="white-space:pre"> </span>var bgObj = document.createElement("div");
<span style="white-space:pre"> </span>bgObj.style.cssText = "position:fixed;z-index: 9997;top: 0px;left: 0px;background: #000000;filter: alpha(Opacity=30); -moz-opacity:0.30;opacity:0.30;";
<span style="white-space:pre"> </span>bgObj.style.width = '100%';
<span style="white-space:pre"> </span>bgObj.style.height = '100%';
<span style="white-space:pre"> </span>body.appendChild(bgObj);
<span style="white-space:pre"> </span>cross.onclick = function () {
<span style="white-space:pre"> </span>body.removeChild(tipWinObj);
<span style="white-space:pre"> </span>body.removeChild(bgObj);
<span style="white-space:pre"> </span>};
<span style="white-space:pre"> </span>okBtn.onclick = function () {
<span style="white-space:pre"> </span>param.funcOk();
<span style="white-space:pre"> </span>body.removeChild(tipWinObj);
<span style="white-space:pre"> </span>body.removeChild(bgObj);
<span style="white-space:pre"> </span>};
<span style="white-space:pre"> </span>noBtn.onclick = function () {
<span style="white-space:pre"> </span>param.funcNo();
<span style="white-space:pre"> </span>body.removeChild(tipWinObj);
<span style="white-space:pre"> </span>body.removeChild(bgObj);
<span style="white-space:pre"> </span>};
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>var param = {
title:'这是一个提示框',
tips:"你点点试试!",
btnOk:'我是确定',
btnNo:'取消',
funcOk:function () {
alert('真2');
},
funcNo:function () {
alert(2);
}
}
</script>
</body>
</html>