我正在为前端可见的 wordpress 插件创建一个表单。使用 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修改):
提前致谢。