Bookmarks of Webdesign

Notes of webdesign. Mainly includes CSS & Javascript

2008-08-22

解決外層DIV高度不適應問題

外層DIV高度不適應是指當內層對象的高度發生變化時,外層對象的高度不能自動進行調節。特別當內層對象使用了padding或margin定義后,問題更加明顯。

內層DIV中的內容


這個問題不是IE專屬的,有時候Firefox下也會出現。


解決方法:插入一個“邏輯占位”層
<div id="clear-div"></div>

其style定義如下
#clear-div{height:0; overflow:hidden;}

效果如下:
內層DIV中的內容

2008-07-14

Positon:fixed在IE6中的解決方法

在版本6以下的IE里,在元素CSS中使用"position:fixed"無法達到將元素抽離數據流并浮動的效果。對此的解決辦法是:

設置CSS屬性
html, body{
height:100%; overflow: auto;}

然后將需要fixed效果的元素設置為
position:absolute;

即可解決問題。

對于一些分辨率低的屏幕,瀏覽器可能會出現兩條豎直滾動條,對此可以有以下解決方法
html{overflow-x:auto; overflow-y:hidden;}
body{height:100%; overflow:auto;}
Original Posts:
Fake position:fixed in IE6

Position:fixed for Internet Explorer

用Javascript獲取瀏覽器屬性

獲取瀏覽器類型:
function CheckBrowser(){
var cb = "Unknown";
if(window.ActiveXObject){
cb = "IE";
}else if(navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
cb = "Firefox";
}else if((typeof document.implementation != "undefined") && (typeof document.implementation.createDocument != "undefined") && (typeof HTMLDocument != "undefined")){
cb = "Mozilla";
}else if(navigator.userAgent.toLowerCase().indexOf("opera") != -1){
cb = "Opera";
}
return cb;
}

獲取瀏覽器寬度和高度:
function test(){
var s = "";
s += "\r\n网页可见区域宽:"+ document.body.clientWidth;
s += "\r\n网页可见区域高:"+ document.body.clientHeight;
s += "\r\n网页可见区域宽:"+ document.body.offsetWidth +" (包括边线的宽)";
s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";
s += "\r\n网页正文全文宽:"+ document.body.scrollWidth;
s += "\r\n网页正文全文高:"+ document.body.scrollHeight;
s += "\r\n网页被卷去的高:"+ document.body.scrollTop;
s += "\r\n网页被卷去的左:"+ document.body.scrollLeft;
s += "\r\n网页正文部分上:"+ window.screenTop;
s += "\r\n网页正文部分左:"+ window.screenLeft;
s += "\r\n屏幕分辨率的高:"+ window.screen.height;
s += "\r\n屏幕分辨率的宽:"+ window.screen.width;
s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;
s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth;
alert(s);
}

注:

上述代碼是能用在html的声明下,在XHMTL1.0的就不行了。应该把BODY换成documentElement,得到文档的父元素。
IE:document.documentElement.offsetHeight/document.documentElement.offsetWidth
FF:window.innerHeight/window.innerWidth

Original Posts:
利用Javascript判断浏览器类型
如何获取浏览器页面区域的宽度和高度?

2007-07-30

ASCII码表



来源:常用ASCII码对照表
更多:ASCII代码表(0-255)

其他JS常用函数

设置表单中所有文本型的成员的值为空(清空)
var form = window.document.forms[0]
for (var i = 0; i if (form.elements.type == "text")
{form.elements.value = "";}


下拉列表框的值
document.forms[0].selectName.options[n].value
(n有时用下拉列表框名称加上.selectedIndex来确定被选中的值)

焦点顺序
document.getElementByid("表单元素").tabIndex = 1

innerHTML的值是表单元素的值:如"how are you"
则innerHTML的值就是:how are you

innerTEXT的值和上面的一样,只不过不会把这种标记显示出来

防止用户对文本框中输入文本:onfocus="this.blur()"

数学函数
Math.PI(返回圆周率)
Math.SQRT2(返回开方)
Math.max(value1,value2)返回两个数中的最大值
Math.pow(value1,10)返回value1的十次方
Math.round(value1)四舍五入函数
Math.floor(Math.random()*(n+1))返回随机数

定义日期型变量
var today = new Date();

日期函数
dateObj.getTime()得到时间
dateObj.getYear()得到年份
dateObj.getFullYear()得到四位的年份
dateObj.getMonth()得到月份
dateObj.getDate()得到日
dateObj.getDay()得到日期几
dateObj.getHours()得到小时
dateObj.getMinutes()得到分
dateObj.getSeconds()得到秒
dateObj.setTime(value)设置时间
dateObj.setYear(val)设置年
dateObj.setMonth(val)设置月
dateObj.setDate(val)设置日
dateObj.setDay(val)设置星期几
dateObj.setHours设置小时
dateObj.setMinutes(val)设置分
dateObj.setSeconds(val)设置秒 [注意:此日期时间从0开始计]

设置时间间隔
setInterval("expr",msecDelay)
或setInterval(funcRef,msecDelay)
或setTimeout

防止链接文字折行
document.body.noWrap=true

返回第n个字符的ASCii码值
string.charCodeAt(n)

测试是否为数值型
isNaN(变量)

定义常量的关键字:const
定义变量的关键字:var

JS窗体与框架相关函数

打开窗口window.open()
关闭窗口:window.close()
窗口本身:self

状态栏的设置
window.status="string";
默认的状态栏文字设置
window.defaultStatus = '文字'

指定当前显示链接的位置
window.location.href="URL"

取出窗体中的所有表单的数量
document.forms.length

关闭文档的输出流
document.close();

创建一个文档元素
document.createElement(), document.createTextNode()

FRAME的表示方式
[window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName

parent代表父亲对象,top代表最顶端对象
打开子窗口的父窗口为:opener

all代表其下层的全部元素

焦点顺序
document.getElementByid("表单元素").tabIndex = 1

innerHTML的值是表单元素的值:如"how are you"
则innerHTML的值就是:how are you

innerTEXT的值和上面的一样,只不过不会把这种标记显示出来

contentEditable可设置元素是否可被修改
isContentEditable返回是否可修改的状态.

isDisabled判断是否为禁止状态
disabled设置禁止状态

addBehavior()是一种JS调用的外部函数文件其扩展名为.htc

window.focus()使当前的窗口在所有窗口之前.

取出该元素在页面中出现的数量
document.all.tags("div(或其它HTML标记符)").length

分为两种窗体输出
模态 window.showModaldialog()
非模态 window.showModeless()

添加到收藏夹
external.AddFavorite("http://www.deepestdark.com","+ Deepest Dark +");

遇到脚本错误时不做任何操作
window.onerror = doNothing;
指定错误句柄的语法为
window.onerror = handleError;

指定当前打开窗口的父窗口
window.opener
(支持opener.opener...的多重继续.)

top指的是框架集中最顶层的框架

窗口重定向
window.navigate("http://www.deepestdark.com");

打印
window.print()

窗口滚动条
window.scroll(x,y)

窗口滚动到位置
window.scrollby

模态显示(在IE4+行,在NN中不行)
showModalDialog("URL"[,arguments][,features]);

退出之前使用的句柄
function verifyClose()
{event.returnValue="we really like you and hope you will stay longer.";}
window.onbeforeunload=verifyClose;

窗体第一次调用时使用的文件句柄
onload()

窗体关闭时调用的文件句柄
onunload()

window.location的属性
protocol(http:)
hostname(example.com)
port(80)
host(example.com:80)
pathname("/a/a.html")
hash("#giantGizmo",指跳转到相应的锚记)
href(全部的信息)

刷新当前页面
window.location.reload()

window.history.back() 返回上一页
window.history.forward()返回下一页
window.history.go(返回第几页,也可以使用访问过的URL)