单行一列
以下是引用片段:
body { margin: 0px; padding: 0px; text-align: center; }
#content { margin-left:auto; margin-right:auto; width: 400px; width: 370px; }
两行一列
以下是引用片段:
body { margin: 0px; padding: 0px; text-align: center;}
#content-top { margin-left:auto; margin-right:auto; width: 400px; width: 370px;}
#content-end {margin-left:auto; margin-right:auto; width: 400px; width: 370px;}
三行一列
以下是引用片段:
body { margin: 0px; padding: 0px; text-align: center; }
#content-top { margin-left:auto; margin-right:auto; width: 400px; width: 370px; }
#content-mid { margin-left:auto; margin-right:auto; width: 400px; width: 370px; }
#content-end { margin-left:auto; margin-right:auto; width: 400px; width: 370px; }
单行两列
以下是引用片段:
#bodycenter { width: 700px;margin-right: auto; margin-left: auto;overflow: auto; }
#bodycenter #dv1 {float: left;width: 280px;}
#bodycenter #dv2 {float: right;width: 410px;}
两行两列
以下是引用片段:
#header{ width: 700px; margin-right: auto;margin-left: auto; overflow: auto;}
#bodycenter { width: 700px; margin-right: auto; margin-left: auto; overflow: auto; }
#bodycenter #dv1 { float: left; width: 280px;}
#bodycenter #dv2 { float: right;width: 410px;}
三行两列
以下是引用片段:
#header{ width: 700px;margin-right: auto; margin-left: auto; }
#bodycenter {width: 700px; margin-right: auto; margin-left: auto; }
#bodycenter #dv1 { float: left;width: 280px;}
#bodycenter #dv2 { float: right; width: 410px;}
#footer{ width: 700px; margin-right: auto; margin-left: auto; overflow: auto; }
单行三列
绝对定位
以下是引用片段:
#left { position: absolute; top: 0px; left: 0px; width: 120px; }
#middle {margin: 20px 190px 20px 190px; }
#right {position: absolute;top: 0px; right: 0px; width: 120px;}
float定位一
xhtml:
以下是引用片段:
<div id='warp'> <div id='column'> <div id='column1'>这里是第一列</div> <div id='column2'>这里是第二列</div> <div ></div> </div> <div id='column3'>这里是第三列</div> <div ></div> </div>
CSS:
以下是引用片段:
#wrap{ width:100%; height:auto;}
#column{ float:left; width:60%;}
#column1{ float:left; width:30%;}
#column2{ float:right; width:30%;}
#column3{ float:right; width:40%;}
.clear{ clear:both;}
float定位二
xhtml:
以下是引用片段:<div id='center' > <h1>This is the main content.</h1> </div> <div id='left' > <h2>This is the left sidebar.</h2> </div> <div id='right' > <h2>This is the right sidebar.</h2> </div>
CSS:
以下是引用片段:
body {margin: 0;padding-left: 200px;padding-right: 190px;min-width: 240px;}
.column {position: relative;float: left;}
#center {width: 100%;}
#left {width: 180px; right: 240px;margin-left: -100%;}
#right {width: 130px;margin-right: -100%;}
两行三列
xhtml:以下是引用片段:<div id='header'>这里是顶行</div> <div id='warp'> <div id='column'> <div id='column1'>这里是第一列</div> <div id='column2'>这里是第二列</div> <div ></div> </P> <P></div> <div id='column3'>这里是第三列</div> <div ></div> </div>
CSS:
以下是引用片段:
#header{width:100%; height:auto;}
#wrap{ width:100%; height:auto;}
#column{ float:left; width:60%;}
#column1{ float:left; width:30%;}
#column2{ float:right; width:30%;}
#column3{ float:right; width:40%;}
.clear{ clear:both;}
三行三列
xhtml:
以下是引用片段:<div id='header'>这里是顶行</div> <div id='warp'> <div id='column'> <div id='column1'>这里是第一列</div> <div id='column2'>这里是第二列</div> <div ></div> </div> <div id='column3'>这里是第三列</div> <div ></div> </div> <div id='footer'>这里是底部一行</div>
CSS:
以下是引用片段:
#header{width:100%; height:auto;}
#wrap{ width:100%; height:auto;}
#column{ float:left; width:60%;}
#column1{ float:left; width:30%;}
#column2{ float:right; width:30%;}
#column3{ float:right; width:40%;}
.clear{ clear:both;}
#footer{width:100%; height:auto;}
本文链接
简述
在IE6、7下,一般的a标签(写好在HTML中的,通过dom操作插入到页面中的a标签)中,假如href的值是一个相对路径时,直接通过a.getAttribute("href"),获取到的不是href的原始值,但可以通过a.getAttribute("href",2)获取到原始值;但如果这种a标签是通过innerHTML插入的话,即使通过a.getAttribute("href",2)也无法获取原始的href值。估计在innerHTML='<a href="/haha/index.html">test</a>'的时候,IE6、7会对其做兼容处理,加入一些东西,这个时候通过outerHTML查看,a的href已经是完整地址-_-! 据说img的src也会出现类似情况。
匆匆路过的……看完上面即可……下面开始瞎扯:
---------------------------------------------------------------------------------------------------------------------------------
原始目标:一个单页应用,想根据a的href属性的值,是否http://开头。如果是,则继续跳转;如果不是,则通过兼容的pushState修改url地址,触发route。
问题:测试IE6、7时,发现a未能正确拦截……
解决办法:问谷姐……得知IE6、7的getAttribute有第二个参数,设为2即可取回原来的属性值。介绍链接如下:
http://msdn.microsoft.com/en-us/library/ie/ms536429%28v=vs.85%29.aspx
看到这里,心里暗爽,马上补一句代码……在按下Ctrl+F5测试后…马上歇菜……为啥不行呢?!百思不得其解……
这时候跟一位朋友瞎扯……不知道扯哪去了……最后在问Frank的过程中,我排除了代码中其他干扰,用以下代码测试:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<a id="a" href="" onclick=".getAttribute(\"href\",2)">test</a>
</body>
</html>
在IE6、7下点击,都弹出大大的“/haha”!!!我就开始怀疑是其他东西在搞鬼了。这时候,想到我的a标签是怎么来的(基于字符串的js模板,innerHTML)……于是,再通过以下代码模拟:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<div id="test"></div>
<script>
document.getElementById("test").innerHTML = '<a id="a" href="/haha/index.html" onclick="alert(this.getAttribute(\'href\',2));return false;">test</a>';
</script>
</body>
</html>
再次测试……sister's……重现问题了!实测,在生成a之后,对a再次setAttribute("href","/haha/index.html",2),再getAttribute("href",2)可以拿回“/haha”。但如果要在模板中做这种事情,似乎太恶心了,果断放弃!还是听Frank的话……简简单单加个属性标识两种链接元素,别钻牛角尖。
再钻一钻-_-!:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<div id="test"></div>
<script>
var test = document.getElementById("test");
调用:
var html = pager("divid", index, 5, 1000, pageChange, { showGoTo: false, showFirst: false });
}
实现:
var theOpt = {
barSize: 5, //分页条显示的页码数
barTemplate: "{bar} 共{totalPage}页{totalCount}条 {goto}", //显示模板
autoHide: true, //是否自动隐藏
showFirst: true, //在totalPage>barSize时是自动否显示第一页链接
showLast: true, //在totalPage>barSize时是自动否显示最后一页链接
showGoTo: true, //是否显示GoTo
autoHideGoTo: true //如果太少是否自动隐藏GoTo
};
if (opt) {
if (opt.barSize)
theOpt.barSize = opt.barSize;
if (opt.barTemplate)
theOpt.barTemplate = opt.barTemplate;
if (opt.autoHide == false)
theOpt.autoHide = false;
if (opt.showFirst == false)
theOpt.showFirst = false;
if (opt.showLast = false)
theOpt.showLast = false;
if (opt.showGoTo == false)
theOpt.showGoTo = false;
if (opt.autoHideGoTo == false)
theOpt.autoHideGoTo = false;
}
var handles = window.myPagerChanges = (function (x) { return x; } (window.myPagerChanges || {}));
if (!myPagerChanges[divPager]) myPagerChanges[divPager] = pageChange;
var startPage = 0; //分页条起始页
var endPage = 0; //分页条终止页
var showFirst = true;
var showLast = true;
if (isNaN(pageIndex)) {
pageIndex = 1;
}
pageIndex = parseInt(pageIndex);
if (pageIndex <= 0)
pageIndex = 1;
if (pageIndex * pageSize > totalCount) {
pageIndex = Math.ceil(totalCount / pageSize);
}
if (totalCount == 0) { //如果没数据
document.getElementById(divPager).innerHTML = "";
return "";
}
var totalPage = Math.ceil(totalCount / pageSize);
if (theOpt.autoHide && totalCount <= pageSize) { //自动隐藏
document.getElementById(divPager).innerHTML = "";
return "";
}
if (totalPage <= theOpt.barSize) {
startPage = 1;
endPage = this.totalPage;
theOpt.showLast = theOpt.showFirst = false;
}
else {
if (pageIndex <= Math.ceil(theOpt.barSize / 2)) { //最前几页时
startPage = 1;
endPage = theOpt.barSize;
theOpt.showFirst = false;
}
else if (pageIndex > (totalPage - theOpt.barSize / 2)) { //最后几页时
startPage = totalPage - theOpt.barSize + 1;
endPage = totalPage;
theOpt.showLast = false;
}
else { //中间的页时
startPage = pageIndex - Math.ceil(theOpt.barSize / 2) + 1;
endPage = pageIndex + Math.floor(theOpt.barSize / 2);
}
if (totalPage <= (theOpt.barSize * 1.5)) {
theOpt.showLast = theOpt.showFirst = false;
}
}
function _getLink(index, txt) {
if (!txt) txt = index;
return "<a href='javascript:;' onclick='myPagerChanges[\"" + divPager + "\"](" + index + ")'>" + txt + "</a>";
}
var barHtml = ""; //分页条
barHtml += pageIndex == 1 ? "" : _getLink(pageIndex - 1, "上一页");
if (theOpt.showFirst) {
barHtml += _getLink(1) + "<span>...</span>";
}
for (var index = startPage; index <= endPage; index++) {
if (index == pageIndex) {
barHtml += "<span >" + index + "</span>";
}
else {
barHtml += _getLink(index);
}
}
if (theOpt.showLast) {
barHtml += "<span>...</span>" + _getLink(totalPage);
}
barHtml += pageIndex == totalPage ? "" : _getLink(pageIndex + 1, "下一页");
var gotoHtml = ""; //goto框及按钮
if (theOpt.showGoTo && theOpt.barTemplate.indexOf("{goto}") > 0) {
if ((theOpt.autoHideGoTo && totalPage > 15) || theOpt.autoHideGoTo == false) {
var txtid = divPager + "_goIndex";
var indexVal = "document.getElementById(\"" + txtid + "\").value";
gotoHtml += "<input type='text' onkeypress='if(event.keyCode==13){myPagerChanges[\"" + divPager + "\"](" + indexVal + ")}' id='" + txtid + "' value=" + pageIndex + " >";
gotoHtml += " <input type='button' value='go' onclick='myPagerChanges[\"" + divPager + "\"](" + indexVal + ")'>";
}
}
//替换模板
var pagerHtml = theOpt.barTemplate.replace("{bar}", barHtml)
.replace("{totalCount}", totalCount)
.replace("{pageIndex}", pageIndex)
.replace("{totalPage}", totalPage)
.replace("{goto}", gotoHtml);
document.getElementById(divPager).innerHTML = pagerHtml;
return pagerHtml;
};
本文链接