如果在浏览器中输入了某个单词,我如何使用 JQuery 进行检查? [英] How can I check with JQuery, if a certain word is typed in the Browser?

查看:11
本文介绍了如果在浏览器中输入了某个单词,我如何使用 JQuery 进行检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很有趣,我想在网站上显示某个 div,只有在该页面上输入了一个秘密单词(没有表单).使用 JQuery 完成此任务的最简单方法是什么?有插件吗?提前感谢欢呼 Tabaluga

This is a funny one, I want to display a certain div on a website only if a secret word is typed on that page (no forms are present). What is the easiest way to accomplish this with JQuery? Are there any Plugins? Thanx in advance cheers Tabaluga

推荐答案

if ( window.addEventListener ) {
        var kkeys = [], konami = "68,73,78,78,69,82"; //this spells dinner
        window.addEventListener("keydown", function(e){
                kkeys.push( e.keyCode );
                if ( kkeys.toString().indexOf( konami ) >= 0 ) {
                    // run code here    
                    $("#text").hide().fadeIn("slow").html('Now the website will appear.');
                }
        }, true);
}

您可以通过以下方式检查哪些字母是什么:​​

you can check what letters are what by doing:

if ( window.addEventListener ) {
    window.addEventListener("keydown", function(e){
        $("#text").append(e.keyCode + " ");
    }, true);
}

这篇关于如果在浏览器中输入了某个单词,我如何使用 JQuery 进行检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆