搜集的可能大家平時沒有注意的,但是比較實用的JS代碼:
(1)點擊文字實現checkbox選項的選定或取消
<input type="checkbox" name="chk" value="chk1" id="idChk1">
<label for="idChk1">點擊選定或取消1</label><br>
<input type="checkbox" name="chk" value="chk2" id="idChk2">
<label for="idChk2">點擊選定或取消2</label><br>
(2)點擊文字實現radio選項的選定
<input type="radio" name="rad" value="rad1" id="idRad1">
<label for="idRad1"> 點擊選定</label><br>
或者
<label for="idRad1"><input type="radio" name="rad" id="idRad1" >imdosop</label>
(3)顯示文檔最后修改日期
<script language="javascript">
document.write(document.lastModified)
</script>
(4)傳遞對象form
<form name="fm1" >
<input type="text" name="txt" value="rad1" onblur="showForm(this.form);" >
</form>
<form name="fm2" >
<input type="text" name="txt" value="rad1" onblur="showForm(this.form);" >
</form>
<script language="javascript">
function showForm(fm){
alert(fm.name);
alert(fm.txt.value);
fm.txt.value="222";
alert(fm.txt.value);
}
</script>
(5)過10秒自動關閉頁面
<script language="JavaScript" >
setTimeout("self.close()",10000);
</script>
(6)改變水平線的特征
<hr size="0" noshade color="#C0C0C0">
(7)在網頁上顯示實時時間
<script language="javascript">
window.onload=function(){
setInterval("document.fm.txtclock.value=(new Date);",1000);
}
</script>
(8)判斷cookie是否可用
<script language="javascript">
window.onload=function(){
if(navigator.cookieEnabled){
alert("Cookie可用");
}
}
</script>
(9)截取小數點后兩位
window.onload=function(){
var a=3454545.4454545;
alert(a.toFixed(2));
}
(10)動態改變字體大小
function reSize(size) {
document.getElementById('imdosop').style.fontSize = size+'px';
}
會繼續補充,也請大家把自己掌握的貼出來共享。。。
天天學習,好好向上——
posted on 2011-12-30 15:30
東頭bing阿頭 閱讀(251)
評論(0) 編輯 收藏 所屬分類:
WEB開發