Thursday 15 April 2010

javascript - How to pass charcode to jquery plugin -



javascript - How to pass charcode to jquery plugin -

i want pass charcode on keyup event jquery plugin.actually till working jquery function , work this. html

<body> <script type="text/javascript" src="working.js"></script> <textarea name="source" id="src1" cols="150" rows="20" onkeyup="showrelated(event)"></textarea> </body>

my working.js

function showrelated(e) { var unicode = e.keycode ? e.keycode : e.charcode; var str = $('#src1').val(); var spacecheck=32; var checkenter=13; if (unicode == spacecheck || unicode==checkenter) { { //my code goes here } }

now need using jquery plugin.so hlml be

<head> <script type="text/javascript" src="jquery.requireplugin.js"></script> </head> <body> <textarea name="source" id="src1" cols="150" rows="20"></textarea></td> <script type="text/javascript"> $("#src1").keyup(function() { $('#src1').pluginmethod(); }); </script> </body>

my jquery.requireplugin.js

(function($) { $.fn.pluginmethod = function() { this.each(function() { var $str = $('#src1'); var som= $str.val(); //here need utilize charcode }); }; })(jquery);

now want know how can pass charcode plugin can utilize within plugin did in workimg.js?

the immediate solution problem given in fiddle- http://jsfiddle.net/q5fgpbyz/2/

where can pass charcode , utilize in plugin-

$("#src1").keyup(function(e) { $('#src1').pluginmethod(e.keycode); });

javascript jquery jquery-plugins

No comments:

Post a Comment