一、按Enter键的效果:
//鼠标事件 document.onkeydown = function(event) { if (event.keyCode == 13 && $("#sendMsgInput").is(":focus")) { sendMsg = $("#sendMsgInput").val().trim(); sendMessage(msgContent,1,null); $("#sendMsgInput").val(""); return false; } };
二、两个循环调用的函数
var callBackTime = function (){ alert("you are so smart!"); setTimeout(callBackTime2, 2000); } var callBackTime2 = function () { alert("you are really pretty good!"); setTimeout(callBackTime, 2000); } window.onload = callBackTime();
三、字符串中出现次数最多的字符
<script> var s = "fggfgfbffnggmvs"; var a = s.split(""); var n = 0,old = 0,name = "",tname = ""; for(var i=0;i<a.length;i++){ name = a[i]; for(var j=0;j<a.length;j++){ if(a[j] == a[i]){ n += 1; } } if(n>old){ tname = name; old = n; } name = ""; n = 0; } alert(tname +" is "+old); </script>