你的錯誤元素上使用絕對定位將讓您的形式保持不變上的錯誤。但是,這將需要額外的標記來維護您的表單顯示。在這個例子中,<span class="item"></span>
一個包裝中加入到您的輸入字段爲錯誤元件提供位置邊界。
注意,對於label
元素設置的屬性會影響您的錯誤標籤,以及。
爲一個例子見http://jsfiddle.net/K5fR8/3/。
全部標記如下:
HTML
<form id="form" action="" method="post">
<p>
<label for="email">Email:</label>
<span class="item">
<input type="text" name="email" id="email" placeholder="Email" value="" class="required" />
</span>
</p>
<p>
<label for="password">Password:</label>
<span class="item">
<input type="password" name="password" id="password" placeholder="Password" value="" class="required" />
</span>
</p>
<p>
<label for=""></label>
<input type="submit" name="submit" id="submit" value="Log In" class="button" />
</p>
CSS
#form p label {
padding-top: 5px;
display: block;
width: 100px;
float: left;
}
#form p .item {
position: relative;
}
#form p .item label.error {
float: none;
position: absolute;
top: 0;
right: -100px; /* Offset by width set on label element */
padding: 0px;
}
謝謝!我不知道插件使用的是標籤。這很好。 – SeanWM 2013-03-21 01:32:30
@SeanWM,不是問題。另外檢查我的答案編輯另一種方法。 – Sparky 2013-03-21 01:34:03
@ if237912print,你不應該在評論中提出新的問題。否則,這個插件的消息位置已經在這裏解決了很多次。你只需要使用[tag:jquery-validate]標籤和'errorPlacement'進行搜索。 – Sparky 2017-08-31 02:34:34