Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/479.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
Javascript hide()函数不使用';不能在jQuery中工作_Javascript_Jquery - Fatal编程技术网

Javascript hide()函数不使用';不能在jQuery中工作

Javascript hide()函数不使用';不能在jQuery中工作,javascript,jquery,Javascript,Jquery,我在表单的jQuery验证方面遇到问题 这是我的javascript文件:test.js $(function() { $('.error').hide(); $(".button").click(function() { $('.error').hide(); var name = $("input#name").val(); if (name == "") { $("label#name_error").show(); $("input#n

我在表单的jQuery验证方面遇到问题

这是我的javascript文件:test.js

$(function() {
$('.error').hide();
    $(".button").click(function() {
        $('.error').hide();
  var name = $("input#name").val();
    if (name == "") {
    $("label#name_error").show();
    $("input#name").focus();
    return false;
  }
});
});
这是我的html文件

<html>
<head>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
</head>
<body>
<div id="contact_form">
<form name="contact" action="">
  <label for="name" id="name_label">Name</label>
  <input type="text" name="name" id="name" size="30" value="" class="text-input" />
  <label class="error" for="name" id="name_error">This field is required.</label>
</form> 
</div>
</body>
</html>

名称
此字段必填。

我将这两个文件与jQuery文件放在服务器上的同一个目录中,但“This field is required.”内容仍然可见。test.js中的hide()函数似乎不起作用。谁能告诉我哪里错了吗?非常感谢

将jquery文件放在
test.js
之前

<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="test.js"></script>


jquery-1.5.2.min.js
引用置于
test.js
引用之上,以便识别它。。它在运行时被隐藏。还有人调试自己的代码吗?任何简单的错误都会导致立即向stackoverflow发送post