【问题标题】:Do not show title text upon hover on input element悬停在输入元素上时不显示标题文本
【发布时间】: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


    【解决方案1】:

    尝试使用 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();

    【讨论】:

    • 谢谢,这个功能可以用,“rel”和“data-Msg”没有用
    【解决方案2】:

    您需要将错误消息存储在其他地方。例如在 JavaScript 数组中:

    var errors = { "emailformat" : "Bad email format" }
    

    并在需要时使用它,从数组而不是从 html 中调用它。

    【讨论】:

    • 您能否指定我如何将它与 jQuery Validation 插件一起使用?我必须为每个输入元素添加特殊规则吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    • 2014-07-21
    相关资源
    最近更新 更多