laucinieks Posted September 15, 2011 Report Share Posted September 15, 2011 (edited) Tātad, mēģinu uztaisīt jquery funkciju - characters left priekš input fielda. Consolē izmetas - val is undefined eval(substringFunction); Headerī norādīju - <script type="text/javascript" src="js/jquery-1.6.3.min.js"></script> <script type="text/javascript" src="js/jquery.limit-1.2.source.js"></script> <script type="text/javascript"> $('#job-title').limit('30','#job-title-chars'); </script> Body - Job title:<strong><div id="job-title-chars">30</div></strong> characters left <form method="post" action=""> <input type="text" value="" name="job-title" id="job-title" /> limit-1.2.source.js - (function($){ $.fn.extend({ limit: function(limit,element) { var interval, f; var self = $(this); $(this).focus(function(){ interval = window.setInterval(substring,100); }); $(this).blur(function(){ clearInterval(interval); substring(); }); substringFunction = "function substring(){ var val = $(self).val();var length = val.length;if(length > limit){$(self).val($(self).val().substring(0,limit));}"; if(typeof element != 'undefined') substringFunction += "if($(element).html() != limit-length){$(element).html((limit-length<=0)?'0':limit-length);}" substringFunction += "}"; eval(substringFunction); substring(); } }); })(jQuery); Kā to labot? Edited September 15, 2011 by laucinieks Quote Link to comment Share on other sites More sharing options...
0 laucinieks Posted September 16, 2011 Author Report Share Posted September 16, 2011 Varbūt vari uzrakstīt piemēru? Quote Link to comment Share on other sites More sharing options...
0 codez Posted September 16, 2011 Report Share Posted September 16, 2011 (edited) http://jsfiddle.net/PV4KM/10/ Edited September 16, 2011 by codez Quote Link to comment Share on other sites More sharing options...
Question
laucinieks
Tātad, mēģinu uztaisīt jquery funkciju - characters left priekš input fielda.
Consolē izmetas -
Headerī norādīju -
Body -
limit-1.2.source.js -
Kā to labot?
Edited by laucinieksLink to comment
Share on other sites
17 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.