我想使用Tooltipster插件来显示jQuery Validate插件生成的表单错误.
jQuery for Validate插件:
$(document).ready(function () {
$('#myform').validate({ // initialize jQuery Validate
// other options,
rules: {
field1: {
required: true,
email: true
},
field2: {
required: true,
minlength: 5
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
jQuery for Tooltipster插件:
$(document).ready(function () {
$('.tooltip').tooltipster({ /* options */ }); // initialize tooltipster
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<form id="myform">
<input type="text" name="field1" />
<input type="text" name="field2" />
<br/>
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
我如何整合这两个jQuery插件的使用,以便验证错误出现在工具提示中?
我使用jquery网站上使用的完全相同的示例进行简单的表单验证; http://docs.jquery.com/Plugins/Validation
但有一点我不明白,示例中的错误消息显示在每个输入字段的右侧.我想在每个输入字段下显示错误.这是如何运作的?我尝试了宽度和填充,但到目前为止没有运气.
我使用的CSS代码略有改动,但仍然非常简单;
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: 0px; vertical-align: bottom; }
p { clear: both; }
fieldset {position: absolute; left: 450px; width: 400px; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
Run Code Online (Sandbox Code Playgroud)
这是jfiddle http://jsfiddle.net/nBv7v/