爲什麼這種情況不起作用?按鍵不匹配時刪除輸入字符
用戶只能輸入'0'和'1',否則應該不輸入。
<body>
<input id="whichkey" />
<script>
$("#whichkey").on("keydown", function(event) {
var x = event.which;
if(x !== '0' || x !== '1'){
var userAns = $("#whichkey").val(),
shortString = userAns.substr(0,(userAns.length -1));
$('#whichkey').val(shortString);
}
});
</script>
</body>
這是一個演示?我沒有看到有疑問或問題,要麼?謝謝你的演示伴侶.. :) – guradio
'如果(X!= '0' || X! ='1'){'這是有意添加與否? – Bhumika107
@ Developer107,這個條件會在不匹配時刪除。 –