gpt4 book ai didi

jquery - 如何将错误消息显示为工具提示?

转载 作者:行者123 更新时间:2023-12-01 05:02:38 25 4
gpt4 key购买 nike

我正在尝试将错误消息显示为工具提示,如下面的链接所示,但这对我不起作用。请让我知道错误是什么。我面临的错误是工具提示错误消息,而不是显示在元素旁边,而是显示在表外的某个位置。我关注的链接:

jQuery override default validation error message display (Css) Popup/Tooltip like

我在这里发布我的代码:

<table border="0" cellpadding="1" cellspacing="1" width="100%">
<tr>
<td colspan="4">MAIN DETAILS
</td>
</tr>
<tr>
<td class="TCDetail_Title">Launch Number:
</td>
<td class="TCDetail_Item">[LaunchID]
</td>
<td class="TCDetail_Title">
</td>
<td class="TCDetail_Item">
</td>
</tr>
<tr>
<td class="TCDetail_Title">Client:
</td>
<td class="TCDetail_Item">[CustName]
</td>
<td class="TCDetail_Title">Job Number:
</td>
<td class="TCDetail_Item">[JobID]-[DashID]
</td>
</tr>
<tr>
<td class="TCDetail_Title">Supplier:
</td>
<td class="TCDetail_Item">[SuppName]
</td>
<td class="TCDetail_Title">Supplier Code:
</td>
<td class="TCDetail_Item">[SupplierID]
</td>
</tr>
<tr>
<td class="TCDetail_Title">Service Date:
</td>
<td class="TCDetail_Item"><input type="text" class="clr" size="8" name="frmServiceDate" id="frmServiceDate" value="[DateScheduled]" class="Sdate">
</td>
<td class="TCDetail_Title">Activity:
</td>
<td class="TCDetail_Item">
<select name="frmActivityType" id="frmActivityType">
<option value='' selected=''>PleaseSelect..</option>
<option value='1'>Inspect</option>
<option value='2'>Audit</option>
</select>
</td>
</tr>
<tr>
<td colspan="4">
<div class="buttons">
<button onclick="checkall();">Submit Timecard</button>
<button>Cancel</button>
</div>
</td>
</tr>
</table>

Jquery 脚本:

<script type="text/javascript">
$.validator.addMethod(
"Sdate",
function (value, element) {

var nowdate=new Date();
if(Date.parse(value) < Date.parse(nowdate))
return (Date.parse(value));

},
"Service Date should not be greater than todays Date."
);
$(document).ready(function(){

$("#Form").validate({
rules:
{
frmActivityType : "required",
frmServiceDate :
{
required: true,
date: true,
Sdate:true
}
},
errorElement: "div",
wrapper: "div", // a wrapper around the error message
errorPlacement: function(error, element) {
offset = element.offset();
error.insertAfter(element)
error.addClass('message'); // add a class to the wrapper
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
error.css('top', offset.top);
}
});
});
</script>

和 CSS 样式 block :

<style>
div.message{
background: transparent url(msg_arrow.gif) no-repeat scroll left center;
padding-left: 7px;
}

div.error{
background-color:#F3E6E6;
border-color: #924949;
border-style: solid solid solid none;
border-width: 2px;
padding: 5px;
}
</style>

提前致谢,斯罗凡提

最佳答案

您可以使用 JQuery UI Postion API 将错误消息定位在元素旁边,

Link to JQuery UI Position API

希望有帮助。

关于jquery - 如何将错误消息显示为工具提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8660979/

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