已采纳回答 / 浪里个吊儿郎
<a href='javascript:function()'>这样写是为了让这个链接不要链接到新页面转而执行一段js代码,和onclick能起到同样的效果,一般来说,如果要调用脚本还是在onclick事件里面写代码,而不推荐href='javascript:function()' 这样的写法。因为href属性里面设置了js代码后,在某些浏览器下可能会引发其他不必要的事件。而且onclick事件会比href属性先执行,所以会先触发 onclick 然后触发href。所以如果不想页面跳转,可以设...
2019-05-24
最新回答 / 半空之境
for(var i = 0 ; i < 5 ; i++){ //如果i<4的话,那么“****”无法被遍历到 for(var j = 0 ; j < arr.length ; j++){ //如果j<7的话,那么“**”无法被遍历到}}
2019-05-24
最新回答 / 玄众妙
不能设置那些不是通过 window.open 创建的窗口或 Tab 的大小。当一个窗口里面含有一个以上的 Tab 时,无法设置窗口的大小。创建一个窗口, 设置宽度与高度为 500px:var w=window.open('','', 'width=100,height=100');w.resizeTo(500,500);
2019-05-24
var num=0;
function startCount() {
document.getElementById('count').value=num;
num=num+1;
setTimeout(startCount,1000)
}
function startCount() {
document.getElementById('count').value=num;
num=num+1;
setTimeout(startCount,1000)
}
2019-05-24
var attime;
function clock(){
var time=new Date();
attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();
document.getElementById("clock").value = attime;
}
setInterval("clock()",1000);
// setInterval(clock,1000);
function clock(){
var time=new Date();
attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();
document.getElementById("clock").value = attime;
}
setInterval("clock()",1000);
// setInterval(clock,1000);
2019-05-24
function openWebpage(){
alert("Welcome to imooc!")
window.open("http://www.imooc.com","_blank","width=600 height=400")
}
alert("Welcome to imooc!")
window.open("http://www.imooc.com","_blank","width=600 height=400")
}
2019-05-24
var score = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var sum = 0;
for(let i = 0;i<score.split(";").length;i++){sum += parseInt((score.split(";"))[i].slice(3,5));}
document.write("班级总分:"+ sum +" 平均分:"+ sum/(score.split(";").length))
var sum = 0;
for(let i = 0;i<score.split(";").length;i++){sum += parseInt((score.split(";"))[i].slice(3,5));}
document.write("班级总分:"+ sum +" 平均分:"+ sum/(score.split(";").length))
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth();
var date = time.getDate();
var week = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
document.write(year+"年"+month+"月"+date+"日 "+week[time.getDay()] + "<br>");
var year = time.getFullYear();
var month = time.getMonth();
var date = time.getDate();
var week = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
document.write(year+"年"+month+"月"+date+"日 "+week[time.getDay()] + "<br>");
function sortNum(a,b) {
return a - b; //正序:a-b 逆序:b-a
}
var myarr = new Array("80","16","50","6","100","1");
document.write(myarr.sort(sortNum));
return a - b; //正序:a-b 逆序:b-a
}
var myarr = new Array("80","16","50","6","100","1");
document.write(myarr.sort(sortNum));
2019-05-23