javascript - jquery 实时打字

标签 javascript jquery live typing

要准确理解我在说什么,请查看此 link

所以,我想摆脱输入框,我的意思是在红色背景的 div 上输入一些内容,例如,当我输入 google 并按 Enter 键时,我想将我发送到 google 网站,当我输入时雅虎向我发送雅虎网站。 我怎样才能做到这一点?我不太擅长 JavaScript。 谢谢!

最佳答案

这可能会有所帮助。

<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

    $('div[contenteditable]').focus();
    $('div[contenteditable]').keypress(function (e) {
    if(e.which == 13) 
    {
       switch ($(this).html()) {
        case 'google':
            document.location = 'http://google.com'
            break;    
        case 'yahoo':
            document.location = 'http://yahoo.com'
            break;
          } 
    } 
    });

});
</script>
<style>
div[contenteditable] { background:red; width:200px;height:20px; padding:5px; }
</style>
</head>
<body>
<div contenteditable></div>
</body>
</html>

关于javascript - jquery 实时打字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7647554/

相关文章:

php - Ajax PHP 实时搜索 - 需要第二步

javascript - Jquery中如何在函数内调用函数?

javascript - Redux 之前的状态已经有了新的状态值

javascript - JQuery 递归函数?

javascript - mvc 中的 AJAX 上传脚本问题

javascript - jQuery has() 总是显示该元素存在

javascript - 当点击 sub li 时,点击功能被调用两次。我该如何解决?

javascript - 实时文本搜索 jquery,错误的选择器?

asp.net - 无法在本地使用 windows live api

jquery - 使用 jQuery 获取选择选项的坐标