After searching for information on the Internet, there are two ways to write JQUERY extension methods, one is to use jquery.fn.extend, and the other is to use jquery.extend. jquery.fn represents jquery.prototype, which adds methods to jquery objects. I just happened to use the extension method and use jquery.fn. Here I will write down the usage of jquery.fn. There are many of them on the Internet, which are very difficult to write For example, when a button is clicked, a textbox value will pop up plus a parameter value
jquery.fn.extend({ alertMessage:function(message ){ var txtboxValue = $(this).val();//Use $(this) to indicate which object the extension method is added to, here refers to $('#textbox') alert(txtboxValue message ); } }); $(function(){ $("input[name='btn' ]").click(function(){ $(' #textbox' ).alertMessage("is a string"); }) })
So I dug out the Jquery Chinese document from the year before last. Browsed briefly about Jquery's methods. I discovered that Jquery is so powerful, why haven’t I discovered it before? So I personally wrote an extension function based on Jquery. The code is as follows:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn