Jump to content
php.lv forumi
  • 0

chars remaining.


laucinieks

Question

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 by laucinieks
Link to comment
Share on other sites

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.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...