内容简介:翻译自:https://stackoverflow.com/questions/7470521/create-function-in-jquery
我正在尝试创建一个jquery函数,并使用下面的代码,但没有得到任何输出.请告诉我制作它的过程.
<script type="text/javascript">
(function($){
$.fn.myplugin = function(){
alert(this.id);
};
})(jQuery);
$("#sample").myplugin();
</script>
你可以在这里看到工作代码 – http://jsfiddle.net/gryzzly/YxnEQ/
请注意,在运行上述代码时,您需要一个id为“sample”的元素才能出现在文档中.此外,这指向jQuery对象,因此为了获取元素id,您需要使用以下任一方法:
alert( this[0].id );
要么
alert( this.attr('id') );
第一个是可取的,因为它更快.
翻译自:https://stackoverflow.com/questions/7470521/create-function-in-jquery
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Getting Started with C++ Audio Programming for Game Development
David Gouveia
Written specifically to help C++ developers add audio to their games from scratch, this book gives a clear introduction to the concepts and practical application of audio programming using the FMOD li......一起来看看 《Getting Started with C++ Audio Programming for Game Development》 这本书的介绍吧!