我對此很新,希望你們中的一個能幫助我?我想要做的是在我的網頁上寫一個關鍵的快捷方式,這是可行的。我只是不知道我會如何循環以使所述人能夠多次使用此功能。我非常感謝任何幫助,也希望我不必過分注意jQuery。Javascript自定義keyshortcut循環故障
這是我的Javascript代碼:
function addZero(i) {
if(i < 10){
i = "0" + i;
};
return i;
};
var d = new Date();
var h = addZero(d.getHours());
var m = addZero(d.getMinutes());
var text = "Press left arrow";
var combo = h + ":" + m;
var isRight=false;
document.onkeyup=function(e){
if(e.which == 39) isRight=false;
};document.onkeydown=function(e){
if (e.which == 39) isRight=true;
if(isRight == true){
document.getElementById('Time_Shortcut').innerHTML = combo + "<br>" + text;
return false;
} else if(e.which == 37){
document.getElementById('Time_Shortcut').style.display = "none";
};
};
我的HTML代碼
<p id="Time_Shortcut"></p>
,只是爲它赫克,連同它的CSS。
#Time_Shortcut {
position: fixed;
opacity: .3;
padding: 20px;
font-family: "Lucida Console", Times, Serif;
color: #BD3A26;
text-decoration: none;
font-size: 22px;
left: 30px;
font-weight: bold;
}
#Time_Shortcut:hover {
opacity: .45;
}
謝謝你的時間,並提前抱歉,如果我搞砸了什麼。
所有的工作如圖所示,我只是不得不將它從document.onkeypress = disptime;到document.onkeydown = disptime;非常感謝你,你救了我很多頭痛。 – eBae