gpt4 book ai didi

jquery numberOfInvalids() 函数不起作用

转载 作者:行者123 更新时间:2023-12-01 01:09:57 25 4
gpt4 key购买 nike

我正在使用 jquery 验证插件 1.9.0 。我从这里下载了该插件:http://bassistance.de/jquery-plugins/jquery-plugin-validation/

我已从此链接 http://docs.jquery.com/Plugins/Validation/Validator/numberOfInvalids 复制了以下代码找出我的表格中的错误数量。但它不起作用。

$(document).ready(function() {
$('a.delete').click(function() {
invalidHandler: function() {
$("#summary").text(validator.numberOfInvalids() + " field(s) are invalid");
}
});
});

然后

<div id="summary" class="summary"> </div>
<a href="#" class="delete">click</a>

我的表单头看起来像这样:

<form class="uniform"  autocomplete="off" id="myForm" enctype="multipart/form-data" action="<?echo base_url();?>addteacher_salary/add " method="post" name="myForm">

我没有在表单中调用任何验证函数,我只是在 head 标记内加载验证插件,并且验证有效。

您能告诉我代码有什么问题吗?

编辑

我的完整表单如下所示:

   <form class="uniform"  autocomplete="off" id="myForm" enctype="multipart/form-data" action="<?echobase_url();?>addteacher_salary/add " method="post" name="myForm">      

<fieldset>
<legend>Select A Teacher</legend>
<dl class="inline">


<dt><label for="teachername">Teacher Name <span class="hello">*</span></label></dt>
<dd>
<?php echo form_dropdown('teacherid', $dropdown_teacher,'', 'class="medium required" id="teacherid"' ); ?>



</dd>

<dt><label for="salary_month">Month of Salary <span class="hello">*</span></label></dt>
<dd>
<?php $month_options = array(
'' => 'Select',
'January' => 'January',
'February' => 'February',
'March' => 'March',
'April' => 'April',
'May' => 'May',
'June' => 'June',
'July' => 'July',
'August' => 'August',
'September' => 'September',
'October' => 'October',
'November' => 'November',
'December' => 'December',
);


echo form_dropdown('salary_month', $month_options,'', 'class="medium required"' );?>

</dd>

<dt><label for="salary_year"> Year of Salary <span class="hello">*</span></label></dt>
<dd>



<?php
$year_options = array(
'' => 'Select',
'2010' => '2010',
'2011' => '2011',
'2012' => '2012',
'2013' => '2013',
'2014' => '2014',

'2015' => '2015',
'2016' => '2016',
'2017' => '2017',
'2018' => '2018',
'2019' => '2019',
'2020' => '2020',
'2021' => '2021',
'2022' => '2022',
'2023' => '2023',
'2024' => '2024',
'2025' => '2025',
'2026' => '2026',
'2027' => '2027',
'2028' => '2028',
'2029' => '2029',
'2030' => '2030',
);


echo form_dropdown('salary_year', $year_options,'', 'class="medium required"' );?>

</dd>

<dt><label for="salary_disbursement_date">Salary Disbursement Date <span class="hello">*</span></label></dt>
<dd>
<input type="text" name="salary_disbursement_date" id="datepicker2" maxlength="10" class="medium required" />

</dd>



<dt><label for="salaryamount">Salary Amount <span class="hello">*</span></label></dt>
<dd>
<input type="text" name="salary_amount" id="salary_amount" value="" class="medium required number" />

</dd>




</dl>

<div class="buttons">
<button id="submit_item" name="submit_item" type="submit" class="button">Submit Button</button>

</div>

</fieldset>
</form>

最佳答案

在调用 numberOfInvalids 之前,请务必在表单上调用 valid:

$(document).ready(function() {
$('a.delete').click(function() {
$("#myForm").valid(); // Make validate calculate the number of invalid fields.
var numInvalid = $("#myForm").numberOfInvalids();

$("#summary").text(numInvalid + " field(s) are invalid");
});
});

示例: http://jsfiddle.net/UURz2/

关于jquery numberOfInvalids() 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8621743/

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