gpt4 book ai didi

javascript - jQuery Textarea 验证不起作用

转载 作者:行者123 更新时间:2023-12-03 04:13:49 24 4
gpt4 key购买 nike

我想用文本区域验证表单。到目前为止,一切都很好。但是当我尝试使用 jQuery validate 初始化文本区域时插件没有任何反应。工具提示不显示。我正在使用tooltipster以及 jQuery-validate 插件。

在控制台中没有显示 JavaScript 错误。

这是表格:

<form name="reportForm" id="reportForm" method="POST">
<div class="form_alt_design">
<label for="the_report"></label>
<textarea name="report" cols="60" rows="4" maxlength="2000" id="the_report" class="report_textbox"></textarea>
</div>
<div id="report_button_container" style="text-align:right;">
<input class="button_large2" type="submit" name="Submit" id="report_submit" value="<?php echo GAME_SUBMIT_REPORT;?>" onclick="submitReport(<?php echo $id.",'".$type;?>')" />
<input class="button_large2" type="submit" name="Submit" id="report_submit" value="<?php echo GAME_SUBMIT_REPORT;?>" onclick="" />

<input type="hidden" name="token" id="token" value="<?php echo $reportToken; ?>" />
</div>

JavaScript 代码:

$(document).ready(function() {
$('#reportForm textarea').tooltipster({
trigger: 'custom',
animation: 'fade',
animationDuration: 250,
delay: 0,
onlyOne: true,
position: 'right',
theme: ['tooltipster-noir', 'tooltipster-noir-customized']
});

// initialize validate plugin on the form
$('#reportForm').validate({

errorPlacement: function (error, element) {

var ele = $(element),
err = $(error),
msg = err.text();
if (msg != null && msg !== '') {
ele.tooltipster('content', msg);
ele.tooltipster('open');
}
}

},
success: function (label, element) {
$(element).tooltipster('hide'); },
unhighlight: function(element, errorClass, validClass) {
$(element).removeClass(errorClass).addClass(validClass).tooltipster('close');
},
rules: {
the_report: {
required:true
}
},
submitHandler: function (form) {

}
});

最佳答案

您已将 required 规则分配给 the_report,但您的 textarea 包含 name="report"

您只能在rules 对象中使用name

rules: {
report: { // <- MUST match the NAME, not the ID
required: true
}
},

您从未说明过 ToolTipster 的版本,但是 here is a working jsFiddle demo using v4.0

REFERENCE: Proper jQuery Validate integration for ToolTipster versions 2, 3, and 4 .

关于javascript - jQuery Textarea 验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44226342/

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