蠱毒傳說
2022-08-04 10:18:01
我想檢查大寫鎖定是否打開,但是使用我的代碼,我只能檢查大寫字母,而不能檢查大寫字母鎖。jQuery('#password').keypress(function(e) { var s = String.fromCharCode( e.which ); if ( s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey ) { jQuery('#caps').show(); } else { jQuery('#caps').hide(); } });這是我的JS代碼。
1 回答

嗶嗶one
TA貢獻1854條經(jīng)驗 獲得超8個贊
你可以使用 event.getModifierState(“CapsLock”) 進行這樣的檢查:-
var inputVal = document.getElementById("customInput");
var textMsg = document.getElementById("warningDiv");
inputVal.addEventListener("keyup", function(event) {
if (event.getModifierState("CapsLock")) {
textMsg.style.display = "block";
} else {
textMsg.style.display = "none"
}
});
#warningDiv{
color: red;
display: none;
}
<input type="text" id="customInput" />
<p id="warningDiv">WARNING! Caps lock is ON.</p>
您也可以在此處檢查我的解決方案-https://codepen.io/Arnab_Datta/pen/gOavXVJ?editors=1111
添加回答
舉報
0/150
提交
取消