我想将 keyup 事件上的字符代码传递给 jquery 插件。实际上到目前为止我一直在使用 jquery 函数,我的工作是这样的。 我的 HTML
<body>
<SCRIPT type="text/javascript" src="working.js"></SCRIPT>
<textarea name="source" id="src1" cols="150" rows="20" onkeyup="showRelated(event)"></textarea>
</body>
我的工作.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
}
}
现在我需要使用 jquery 插件来完成它。所以我的 hlml 将是
<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>
我的jquery.requireplugin.js
(function($) {
$.fn.pluginmethod = function() {
this.each(function() {
var $str = $('#src1');
var som= $str.val();
//here i need to use charcode
});
};
})(jQuery);
现在我想知道如何将字符代码传递给插件,以便我可以像在 workimg.js 中那样在插件中使用它?
最佳答案
fiddle 中给出了您问题的直接解决方案-http://jsfiddle.net/q5fgpbyz/2/
您可以简单地传递 charCode 并在插件中使用它-
$("#src1").keyup(function(e) {
$('#src1').pluginmethod(e.keyCode);
});
关于javascript - 如何将字符代码传递给jquery插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26711507/