开发者

Call a function on any event of textarea

I wanted to call a signle function on any event happens for <textarea>.

How do I achieves this开发者_开发技巧.

Please do suggest me folks, jquery is preferable.

Thanks,

-Pravin


Try something like this :

$("textarea").each(
                        function(element) {

                            $(element).bind({

                                focusin: function() {
                                    $(this).toggleClass('ui-state-focus');
                                },
                                focusout: function() {
                                    $(this).toggleClass('ui-state-focus');
                                }
                            });

                        }
   );


You can do something like this:

$('#textarea_id').change(function(){
  // your code...
});

That code will run when text of textarea changes. If you want, you can also run the code when key is pressed with keyup or keypress event:

$('#textarea_id').keypress(function(){
  // your code...
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜