Last active
December 16, 2015 09:09
-
-
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 :).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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