内容简介:翻译自: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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Python 拓展之特殊函数(lambda 函数,map 函数,filter 函数,reduce 函数)
- Python 函数调用&定义函数&函数参数
- python基础教程:函数,函数,函数,重要的事说三遍
- C++函数中那些不可以被声明为虚函数的函数
- 017.Python函数匿名函数
- 纯函数:函数式编程入门
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Distributed Systems
Sukumar Ghosh / Chapman and Hall/CRC / 2014-7-14 / USD 119.95
Distributed Systems: An Algorithmic Approach, Second Edition provides a balanced and straightforward treatment of the underlying theory and practical applications of distributed computing. As in the p......一起来看看 《Distributed Systems》 这本书的介绍吧!