javas
说明:如要看到下面代码显示效果,请将代码复制粘贴到“运行代码框”,再点“运行代码”!
★显示当前时间
2012年7月31日(星期二)22时22分59秒
<script>
var my=new Date(),ar,th,te,myD,h,m,s,t,d=new Array
("日)","一)","二)","三)","四)","五)","六)");
ar=my.getYear() ;
th=my.getMonth()+1;
te=my.getDate();
myD=my.getDay();
h=my.getHours();
m=my.getMinutes();
s=my.getSeconds();
t=my.getTime();
alert("1970 年1月1日至今的毫秒数:\n\n"+t);
document.write(""+ar+"年"+th+"月"+te+"日"+"(星期"+d[myD]+h+"时"+m+"分"+s+"秒");
</script>
★最简的静态时间js代码1
2012-7-29 22:28:30
<script language=vbscript>document.write now</script>
★最简的静态时间js代码2
2012年7月30日 星期一 9:58 下午
<div align="left">
<script language="JavaScript">
<!---
today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = "<FONT COLOR=black>" + ((hours >12) ? hours -12 :hours); timeValue += ((minutes < 10) ? "<BLINK><FONT COLOR=black>:</FONT></BLINK>0" : "<BLINK><FONT COLOR=black>:</FONT></BLINK>") + minutes+"</FONT></FONT>";
timeValue += (hours >= 12) ? " 下午 " : " 上午 ";
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray("<font color=RED>星期日","<font color=black>星期一","<font color=black>星期二","<font color=black>星期三","<font color=black>星期四","<font color=black>星期五","<font color=red>星期六"); document.write("<font color=black>",today.getYear(),"<font color=black>年","<font color=black>",today.getMonth()+1,"<font color=black>月","<font color=black>",today.getDate(),"<font color=black>日 </FONT>",d[today.getDay()+1]," ",timeValue); //-->
</script></div>
★最简的静态时间js代码3
现在是:2012年7月31日22时18分50秒
<script>
var n=new Date()
document.write("现在是:"+n.getYear()+"年"+(n.getMonth()+1)+"月"+n.getDate()+"日"+n.getHours()+"时"+n.getMinutes()
+"分"+n.getSeconds()+"秒")
</script>
★最简的动态时间js代码
2012年7月29日星期日 21:58:33-余日
<div id="xuhui">
<script>
setInterval("xuhui.innerHTML=new Date().toLocaleString();",1000);
</script>
</div>
这个,请将代码复制粘贴到“在线编辑器”中测试!
★获取文档中的值
<input type="text"name="xh"id="xh"value="请你输入"><br><br>
<input type="button" name="button" value="获取"on
<script>
function aa() {
var b=document.getElementById("xh").value;
alert("你输入的是:"+b);
}
</script>
★检验文本框是否为空
<input type="text"name="xh"id="xh"value=""><br><br>
<input type="button" name="button" value="获取"on
<script>
function aa() {
var b=document.getElementById("xh").value;
if (b=="" || b==null) {
alert("你的文本框内是空的!");
}else {
alert("你输入的是:"+b);
}
}
</script>
★检测输入的是否是数字
<input type="text"name="xh"id="xh"value="请你输入"><br><br>
<input type="button" name="button" value="检测"on
<script>
function aa() {
if (isNaN(document.getElementById("xh").value)==tr) {
alert("你输入的不是数字!");
}
}
</script>
★检测输入的字符是否达到某个数
<input type="text"name="xh"id="xh"value=""><br><br>
<input type="button" name="button" value="获取"on
<script>
function aa() {
if (document.getElementById("xh").value.length<6) {
alert("你输入的少于6个字符!");
}else {
alert("你输入的已达到或超过了6个字符!");
}
}
</script>
★检测输入字符的个数
<script>
function aa() {
alert("你已经输入了"+document.getElementById("words").value.length+"个字母")
}
</script>
<textarea rows="3" cols="20" id="words"></textarea><br>
<input type="button" value="检测"on
★自动显示输入字符的个数
<script>
function ch(wh) {
var nt=document.getElementById("char");
ou=wh.value.replace(/[^\-\?]/g,"aa");
nt.innerHTML="<font color=#FF0000>"+ou.length+"</font>";
}
</script>
你输入了<span id="char">0</span>个字符<br>
<textarea rows="3" cols="20" id="words"on
★文本框随输入字符自动增长且显示字符个数
<script>
function checkLength(which) {
var oTextCount = document.getElementById("char");
iCount = which.value.replace(/[^\-\?]/g,"aa");
oTextCount.innerHTML = "<font color=#FF0000>"+ iCount.length+"</font>";
which.style.border = '1px dotted #FF0000';
which.size=iCount.length+2;
}
</script>
<input name="words" size="2" on
<span id="char">0</span>个字符
评论