gpt4 book ai didi

javascript - jQuery 快速问题

转载 作者:行者123 更新时间:2023-11-28 11:27:54 26 4
gpt4 key购买 nike

我收到这样的错误:

未捕获类型错误:无法读取未定义的属性“form”

Firebug 说这一行是罪魁祸首:

if($("emailPost2").valid())

这是我所有的 jQuery 代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js"></script>

<script type="text/javascript" src="https://github.com/jzaefferer/jquery-validation/raw/master/jquery.validate.js"></script>

<script type="text/javascript" charset="utf-8">
$(function(){
$("emailPost2").validate({
rules: {
emailAddress: {
required: true,
email: true
}
}
});
$('#zonePlus').click(function() {
$('#zoneNotif').submit();
});

$('#searchPost').submit(function(event) {
if ($(this).find('#searchBox').val() == '') {
event.preventDefault();
}
});
$("#searchBox").autocomplete({
source: 'php/searchAC.php'
});
$("button, input:submit, input:button, a#jql, input:radio").button();

$('#emailJQButton').live('click',function() {
$("#emailModal").dialog('open');
});

$('#eb1').live('click',function() {
$('#emailPost').submit();
$("#emailModal").dialog('close');
});

$('#eb2').live('click',function() {
if($("emailPost2").valid())
{
$('#emailPost2').submit();
$("#emailModal").dialog('close');
}
});
});
</script>

如果有效,valid() 应该返回 true,但我只是得到上面提到的错误而不是任何结果。

编辑:以下是表单的 HTML 代码:

<div id="emailModal">
<form action="php/emailPost.php" method="POST" class="inline" id="emailPost2">
<label name="error"></label>
<input type="text" value="Enter an Email" class="required email" name="emailAddress" style="display: inline-block;">
<input type="button" value="Email" id="eb2"/>
<input type="hidden" name="passedCoupID" value="1"/>
</form>
</div>

最佳答案

看起来问题很简单,就是您忘记了 id 选择器中的 #:

$("#emailPost2").valid()

(而不是当前的 $("emailPost2").valid())

关于javascript - jQuery 快速问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5237137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com