Skip to content

Instantly share code, notes, and snippets.

@kloneets
Last active December 16, 2015 09:09
Show Gist options
  • Save kloneets/5411255 to your computer and use it in GitHub Desktop.
Save kloneets/5411255 to your computer and use it in GitHub Desktop.
Jquery plugins, kas uz fokusu nonullē input lauka defaulto vērtību, bet uz blūru skatās, ja ir tukšs, tad parāda defaulto, bet, ja pilns, tad nedara neko :).
/**
* Copyright (c) 2013 Janis Rublevskis - koko@xit.lv | http://nobody.lv
* Licensed under MIT.
* @author Janis Rublevskis
* @version 1.0.0.0
*/
(function ($) {
$.fn.checkFocus = function() {
var obj = $(this);
obj.each(function(){
var thisTitle = $(this).val();
$(this).focus(function(){
if($(this).val() == thisTitle) {
$(this).val('');
}
});
$(this).blur(function(){
if($.trim($(this).val()) == '') {
$(this).val(thisTitle);
}
});
});
};
})(jQuery);
//usage
$(function(){
$('input').checkFocus();
//or
$('.myClass').checkFocus();
//or
$('#myId').checkFocus();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment