搜集的可能大家平時(shí)沒(méi)有注意的,但是比較實(shí)用的JS代碼:
(1)點(diǎn)擊文字實(shí)現(xiàn)checkbox選項(xiàng)的選定或取消
<input type="checkbox" name="chk" value="chk1" id="idChk1">
<label for="idChk1">點(diǎn)擊選定或取消1</label><br>
<input type="checkbox" name="chk" value="chk2" id="idChk2">
<label for="idChk2">點(diǎn)擊選定或取消2</label><br>
(2)點(diǎn)擊文字實(shí)現(xiàn)radio選項(xiàng)的選定
<input type="radio" name="rad" value="rad1" id="idRad1">
<label for="idRad1"> 點(diǎn)擊選定</label><br>
或者
<label for="idRad1"><input type="radio" name="rad" id="idRad1" >imdosop</label>
(3)顯示文檔最后修改日期
<script language="javascript">
document.write(document.lastModified)
</script>
(4)傳遞對(duì)象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)過(guò)10秒自動(dòng)關(guān)閉頁(yè)面
<script language="JavaScript" >
setTimeout("self.close()",10000);
</script>
(6)改變水平線(xiàn)的特征
<hr size="0" noshade color="#C0C0C0">
(7)在網(wǎng)頁(yè)上顯示實(shí)時(shí)時(shí)間
<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)截取小數(shù)點(diǎn)后兩位
window.onload=function(){
var a=3454545.4454545;
alert(a.toFixed(2));
}
(10)動(dòng)態(tài)改變字體大小
function reSize(size) {
document.getElementById('imdosop').style.fontSize = size+'px';
}
會(huì)繼續(xù)補(bǔ)充,也請(qǐng)大家把自己掌握的貼出來(lái)共享。。。
天天學(xué)習(xí),好好向上——
posted on 2011-12-30 15:30
東頭bing阿頭 閱讀(250)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
WEB開(kāi)發(fā)