js网页输入密码才显示

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

<script>
$(document).ready(function(){
  var letterCombination = "abc"; // 设置特定的字母组合

  var inputText = ""; // 用户输入的文本
	var space = false;
  $(window).keydown(function(event){
    var keyPressed = String.fromCharCode(event.which); // 获取按下的键盘字符
	console.log("用户输入了:",keyPressed);
    // 将按下的字符添加到用户输入的文本中
    inputText += keyPressed.toLowerCase();
	
	if (event.keyCode == 32) {
	  space = true;
	  inputText = "";
	  console.log('输入已被清空')
	}

    if (inputText === letterCombination) {
      // 当用户输入的文本与特定的字母组合相同时,执行相应的操作
	  alert('kill!');
      console.log("用户输入了特定的字母组合!");
	  inputText = ""; 
    }
  });
});
</script>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/xgocn/article/details/133031725