- 获取当前日期
<script type="text/javascript"> var mydate=new Date(); var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; var today = mydate.getDay(); document.write("今天是:" + weekday[today]); </script>
-
当前时间推出两小时
<script type="text/javascript"> var mydate=new Date(); document.write("当前时间:"+mydate+"<br>"); mydate.setTime( mydate.getTime() + 2* 60 * 60 * 1000); document.write("推迟二小时时间:" + mydate); </script>
-
降序排列数组
<script type="text/javascript"> function sortNum(a,b) { return b-a; } var myarr = new Array("80","16","50","6","100","1"); document.write(myarr.sort(sortNum)); </script>
- 判断浏览器
function validB(){
var u_agent = navigator.userAgent;
var B_name="非主流浏览器!";
if(u_agent.indexOf("Firefox")>-1){
B_name="Firefox";
}else if(u_agent.indexOf("Chrome")>-1){
B_name="Chrome";
}else if(u_agent.indexOf("MSIE")>-1&&u_agent.indexOf("Trident")>-1){
B_name="IE(8-10)";
}
document.write("浏览器:"+B_name+"<br>");
document.write("u_agent:"+u_agent+"<br>");
}
- 计数器
<label id="txt1"></label>
<script type="text/javascript">
var num=0;
function count()
{
document.getElementById("txt1").innerHTML=num;
num = num +1;
setTimeout("count()",1000);
}
count();
</script>
删除某节点下的元素
function clearText() {
var content=document.getElementById("content");
var childCount = content.childNodes;
// 在此完成该函数
for(var i=childCount.length-1;i>=0;i--)
{
content.removeChild(content.childNodes[i]);
}
}