我在wordpress插件中为前端创建了一个窗体。 使用JQuery验证方法,我有问题在每个字段下精确定位每个错误。从jQuery验证插件定位消息
所以这是我的脚本:
function validate_init() { ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#form_register').validate({
rules: {
ragsoc: {
required: true,
minlength: 2
},
piva: {
required: true,
digits: true,
},
gruppo: {
required: true,
},
},
messages: {
ragsoc: "Inserire la ragione sociale.",
piva: "Solo numeri accettati.",
gruppo: "inserire un valore.",
},
errorElement: "div",
errorPlacement: function(error, element) {
error.insertAfter(element);
},
});
});
</script>
<?php }
add_action('wp_footer', 'validate_init', 999);
,这是我的表单:
<?php echo '<form id="form_register" method="post" action="'.$pluginfolder.'/submit.php">'; ?>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td colspan="3"><label for="ragsoc">Ragione sociale *</label>
<input type="text" name="ragsoc" id="long" /></td>
</tr>
<tr>
<td><label for="piva">Partita Iva *</label>
<input type="text" name="piva" id="tris" /></td>
<td><label for="codfisc">Codice Fiscale</label>
<input type="text" name="codfisc" id="tris" /></td>
<td><label for="gruppo">Gruppo</label>
<input type="text" name="gruppo" id="tris" /></td>
</tr>
<tr>
<td>
<label for="codice">Codice</label>
<input type="text" name="codice" id="tris" />
</td>
<td>
<label for="insegna">Insegna *</label>
<select id="tris" name="insegna">
<option value=""><em>Scegli...</em></option>
<option value="option_1">option_1</option>
<option value="option_2">option_2</option>
</select>
</td>
<td>
<label for="rapporto">Rapporto *</label>
<select id="tris" name="rapporto">
<option value=""><em>Scegli...</em></option>
<option value="option_1">option_1</option>
<option value="option_2">option_2</option>
<option value="option_3">option_3</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="button" id="button" value="Invia" />
<input type="reset" name="button2" id="button2" value="Cancella" />
</tr>
</table>
</form>
最后,这是我的CSS:
div.error{
color: #f33;
padding: 0;
margin: 2px 0 0 0;
font-size: 0.7em;
padding-left: 18px;
background-image: url('error.png');
background-position: 0 0;
background-repeat: no-repeat; }
它的所有工作正常,但位置的错误信息是错误的三个列字段错误重叠如下图所示:
我怎样才能获得该效果(与Photoshop修改):
预先感谢。
该死的......问题是输入的重复ID而不是使用类。现在它工作正常。我只是用class替换id,问题就解决了。再次感谢。 – Stalvatero 2013-02-27 11:05:33