定時自動轉頁
<script>setTimeout('document.location.href="[url]"',5000)</script>
返回前一頁
<a href="javascript:history.back()">返 回</a>
關閉視窗
<script>javascript:window.close()</script>
彈出訊息視窗
<script>window.alert("hi!");</script>")
定焦點到文字框的末尾
function focusEnd(){
if(field.createTextRange){
var r = field.reateTextRange();
r.moveStart('character',field.value.length);
r.collapse();
r.select();
}
}
規範文章中的圖片
<img onload='javascript:if(this.width>790)this.style.width=790;'
onclick='javascript:window.open(this.src);'
style='CURSOR:hand'
onmousewheel='return bbimg(this)'>
function bbimg(o){
var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
return false;
}
js檔案中的中文問題
web application的編碼規則是utf-8,那麼js檔案中如果有中文就會出現亂碼(有可能是其它的頁面不正常的情況)
解決這個問題請在引用javascript的地方加上charset="gb2312"或者charset="big5"
例如:<script type="text/javascript" language="javascript" src="scripts/function.js" charset="gb2312"></script>
視窗無邊框
<a href="#" onclick="window.open('test.htm','','width=300,height=450,toolbar=0,menubar=0,location=0')">開啟</a>
輸入框長度隨輸入內容的長度而改變
<input type="text" style="overflow-x:visible;width:60;">
點擊單選框就直接啟用連結
第一步:把如下代碼加入到<head>地區中
<SCRIPT>
function go(loc) {
window.location.href = loc;
}
</script>
第二步:把如下代碼加入到<body>地區中
<form name="form">
<input type="radio" name="loc" onClick="go('#');">
選中即激發了超連結<br>
<input type="radio" name="loc" onClick="go('#l');">
選中即激發了超連結<br>
<input type="radio" name="loc" onClick="go('#');">
選中即激發了超連結<br>
</form>