【发布时间】:2012-04-14 21:35:14
【问题描述】:
我正在使用 jQuery Validate 插件并将错误消息存储在标题中,例如:
<input type="text" name="email" class="required email" title="Bad email format" />
我不希望在悬停时显示标题文本“错误的电子邮件格式”。如何禁用此功能(如果可能)?
【问题讨论】:
标签: jquery jquery-validate html-input
我正在使用 jQuery Validate 插件并将错误消息存储在标题中,例如:
<input type="text" name="email" class="required email" title="Bad email format" />
我不希望在悬停时显示标题文本“错误的电子邮件格式”。如何禁用此功能(如果可能)?
【问题讨论】:
标签: jquery jquery-validate html-input
尝试使用 rel="Bad email format" insted 标题或 html 数据属性,如 data-errorMssg="Bad email format",如果您不能使用它们,这里是一个提取代码来隐藏标题
(function($){
$.fn.hide_my_tooltips = function() {
return this.each(function() {
$(this).hover(function(e) {
// mouseover
var $this=$(this);
$this.data("myTitle",$this.attr("title")); //store title
$this.attr("title","");
}, function() {
// mouseout
var $this=$(this);
$this.attr("title",$this.data("myTitle")); //add back title
});
$(this).click(function() {
var $this=$(this);
$this.attr("title",$this.data("myTitle")); //add back title
});
});
};
})(jQuery);
// 在文档就绪函数中使用正确的选择器调用 JQ 函数。 $("输入").hide_my_tooltips();
【讨论】:
您需要将错误消息存储在其他地方。例如在 JavaScript 数组中:
var errors = { "emailformat" : "Bad email format" }
并在需要时使用它,从数组而不是从 html 中调用它。
【讨论】: