Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery响应表单输入框中键入的特定关键字_Jquery - Fatal编程技术网

如何使用jQuery响应表单输入框中键入的特定关键字

如何使用jQuery响应表单输入框中键入的特定关键字,jquery,Jquery,我希望有一个带有输入文本字段的表单,并且如果用户键入单词“hello”(不区分大小写的匹配),能够做出响应(显示一个警告文本框) 我需要捕获什么事件(文本输入字段似乎没有更改事件) 这就是我到目前为止所做的: <html> <head> <title>Some test</title> <script type="text/javascript" src="jquery.js"></script>

我希望有一个带有输入文本字段的表单,并且如果用户键入单词“hello”(不区分大小写的匹配),能够做出响应(显示一个警告文本框)

我需要捕获什么事件(文本输入字段似乎没有更改事件)

这就是我到目前为止所做的:

<html>
   <head>
      <title>Some test</title>
      <script type="text/javascript" src="jquery.js"></script>
   </head>
   <body>
      <form action="something.php" method="post">
         Field1: <input id="field1" type="text">
      </form>
<script type="text/javascript">
$(document).ready(function(){
  // what?
});
</script>   
   </body>
</html>

一些测试
字段1:
$(文档).ready(函数(){
//什么?
});
试试:

是的

<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
<link href="style.css" type="text/css" rel="stylesheet"> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
    $(function(){
        $('#input1').change(function(){
            if ($(this).val() == 'hello'){
                alert('you typed hello !');
            }
        });
    });
</script>
<style type="text/css"></style>
</head>
<body>
    <input id="input1" type="text" />
</body>
</html>

样品
$(函数(){
$('#input1')。更改(函数(){
if($(this).val()=='hello'){
警惕(“你打了你好!”);
}
});
});

我会使用keyup事件,因为它更适合您打算做的事情。 相同的代码已经发布,只是不同的事件

<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
<link href="style.css" type="text/css" rel="stylesheet"> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
    $(function(){
        $('#input1').change(function(){
            if ($(this).val() == 'hello'){
                alert('you typed hello !');
            }
        });
    });
</script>
<style type="text/css"></style>
</head>
<body>
    <input id="input1" type="text" />
</body>
</html>