2013-02-12 70 views
2

我使用jquery.hint.js。在页面加载everiting罚款,但是当我使用后退浏览器按钮焦点不隐藏提示。焦点不隐藏浏览器后退按钮提示(jquery.hint.js)

jQuery.fn.hint = function (blurClass) { 
    if (!blurClass) { 
     blurClass = 'blur'; 
    } 

    return this.each(function() { 
     // get jQuery version of 'this' 
     var $input = jQuery(this), 

     // capture the rest of the variable to allow for reuse 
      title = $input.attr('title'), 
      $form = jQuery(this.form), 
      $win = jQuery(window); 

     function remove() { 
      if ($input.val() === title && $input.hasClass(blurClass)) { 
       $input.val('').removeClass(blurClass); 
      } 
     } 

     // only apply logic if the element has the attribute 
     if (title) { 
      // on blur, set value to title attr if text is blank 
      $input.blur(function() { 
       if (this.value === '') { 
        $input.val(title).addClass(blurClass); 
       } 
      }).focus(remove).blur(); // now change all inputs to title 

      // clear the pre-defined text when form is submitted 
      $form.submit(remove); 
      $win.unload(remove); // handles Firefox's autocomplete 
     } 
    }); 
}; 

例如在正常的网页加载:使用回浏览器按钮后http://prntscr.com/sik0d 例如:http://prntscr.com/sikap(剂量不掩饰对焦点的提示,它只是添加文本输入字段)

如何解决这个问题。如何强制这个脚本重新加载后退按钮?谢谢

回答

1

我终于发现jquery.hint.js女巫包括使用浏览器后退按钮的修复程序。因此,这里是一个链接:https://gist.github.com/madmanlear/1723896

的JavaScript:

(function ($) { 

$.fn.hint = function (blurClass) { 
    if (!blurClass) blurClass = 'blur'; 

    return this.each(function() { 
     var $input = $(this), 
      title = $input.attr('placeholder'), 
      $form = $(this.form), 
      $win = $(window); 

     function remove() { 
      if ($input.val() === title) { 
       $input.val('').removeClass(blurClass); 
      } 
     } 

     // only apply logic if the element has the attribute 
     if (title) { 
      // on blur, set value to title attr if text is blank 

      $input.blur(function() { 
       if (this.value === '' || this.value == title) { 
        $input.val(title).addClass(blurClass); 
       } 
      }).focus(remove).blur(); // now change all inputs to title 

      // clear the pre-defined text when form is submitted 
      $form.submit(remove); 
      $win.unload(remove); // handles Firefox's autocomplete 
     } 
    }); 
}; 

})(jQuery);