mdui has a built-in lightweight JavaScript utility library with a jQuery-like API and chaining style, but it is only one-sixth the size of jQuery.
You can use mdui.$ to call the library, but it's better to store mdui.$ in a short variable for convenience, for example:
var $ = mdui.$;In the subsequent documentation, $ is used to represent mdui.$.
$() | This method has multiple usages: A CSS selector can be passed as a parameter to return a JQ object containing the matching elements. This method is implemented via DOM elements, any array, NodeList, or JQ objects can be passed to return a JQ object containing the specified elements. An HTML string can be passed to return a JQ object containing the DOM created based on the HTML. A function can be passed, which will be called after the DOM is fully loaded. |
$.extend() | If only one object is passed, the properties in that object will be merged into the JQ object, which is equivalent to adding new functionality under the JQ namespace. If two or more objects are passed, properties from all objects are added to the first object, and the merged object is returned. |
$.fn.extend() | Extend methods on the JQ prototype chain. |
$.param() | Serialize an object or array and return a string suitable for URL parameters. If the parameter is an array, it must be in the same format as the return format of |
$.each() | Traverse an array or object. The return value is the first parameter, i.e., the array or object being traversed. The first parameter of the function is the index position of the array or the key of the object; the second parameter is the value at the corresponding position of the array or object. The |
$.merge() | Append elements of the second array to the first array and return the merged array. |
$.unique() | Filter out duplicate elements in the array. |
$.map() | Traverse an array or object and return a new array composed of the return values of the function. The first parameter of the function is the value at the corresponding position of the array or object, and the second parameter is the index position of the array or the key of the object. The function can return any value. If it returns an array, it will be flattened; if it returns |
$.contains() | Determine whether a parent node contains a child node, returning a boolean value. |
.is() | Returns The parameter can be a CSS selector, DOM element, array of DOM elements, JQ object, or callback function. When the parameter is a callback function, its first parameter is the index position, the second parameter is the current element, and |
.length | Return the number of elements in the current collection. |
.each() | Traverse the current collection and execute a function for each element in the collection. If the function returns The first parameter of the function is the index position of the element, and the second parameter is the current element. |
.map() | Traverse the current collection and execute a function for each element, returning a new collection composed of the function return values. If the function returns The first parameter of the function is the index position of the element, and the second parameter is the current element. |
.eq() | Return a collection containing only the element at the specified index position. |
.first() | Return a collection containing only the first element. |
.last() | Return a collection containing only the last element. |
.get() | Return the element at the specified index position. If no parameter is passed, return an array composed of all elements in the collection. |
.index() | If no parameter is passed, return the index position of the first element in the collection relative to its siblings. If a CSS selector is passed as a parameter, return the index position of the first element in the collection relative to the elements matching the CSS selector. If a DOM element is passed, return the index of that DOM element in the collection. If a JQ object is passed, return the index position of the first element in that object within the current collection. |
.slice() | Return a subset of the current collection. The first parameter is the start position of the subset, and the second parameter is the end position; if the second parameter is not passed, it includes all elements from the start position to the end. |
.filter() | Filter elements matching the specified expression from the current collection. The parameter can be a CSS selector, DOM element, array of DOM elements, or callback function. When the parameter is a function, its first parameter is the index position, the second parameter is the current element, and |
.not() | Filter elements from the current collection that do not match the specified expression. The parameter can be a CSS selector, DOM element, array of DOM elements, or callback function. When the parameter is a function, its first parameter is the index position, the second parameter is the current element, and |
.hasClass() | Determine whether the first element in the collection contains the specified CSS class. |
.addClass() | Add CSS classes to each element in the collection; multiple class names can be separated by spaces. A callback function that returns CSS class names can also be passed. The first parameter of the function is the index position, the second parameter is the original CSS class name on the element, and |
.removeClass() | Remove CSS classes from elements in the collection; multiple class names can be separated by spaces. A callback function that returns CSS class names can also be passed. The first parameter of the function is the index position, the second parameter is the original CSS class name on the element, and If no parameter is passed, the |
.toggleClass() | Toggles a CSS class for elements in the collection: if the class is present, it is removed; otherwise, it is added. Multiple class names can be separated by spaces. A callback function that returns CSS class names can also be passed. The first parameter of the function is the index position, the second parameter is the original CSS class name on the element, and |
.prop() | Get the attribute value of the first element in the collection. Can also set attribute values for all elements in the collection. The attribute value can be the return value of a callback function. The first parameter of the callback function is the index position of the element, the second parameter is the original attribute value on the element, and If the attribute value or the return value of the callback function is Multiple attributes can also be set simultaneously by passing an object. |
.removeProp() | Remove specified attribute values from all elements in the collection. |
.attr() | Get the property value of the first element in the collection. Can also set property values for all elements in the collection. The property value can be the return value of a callback function. The first parameter of the callback function is the index position of the element, the second parameter is the original property value on the element, and If the property value or the return value of the callback function is Multiple properties can also be set simultaneously by passing an object. |
.removeAttr() | Remove specified property values from all elements in the collection; multiple property names can be separated by spaces. |
.val() | Get the value of the first element in the collection. If the element is Can also set values for all elements in the collection. The value can be a string, number, array of strings, or a callback function. If the value is a callback function, its first parameter is the index position of the element, the second parameter is the original value of the element, and If the element is If the value or the function return value is |
.text() | Get the text content of all elements in the collection (including their descendants) Can also set the text for all elements in the collection. The set value can be a string, number, boolean, or callback function. If it is a callback function, the first parameter is the index position of the element, the second parameter is the original text content of the element, and If the value or the return value of the callback function is |
.html() | Get the HTML content of the first element in the collection. Can also set the HTML content for all elements in the collection. The set value can be an HTML string, DOM element, or callback function. If it is a callback function, the first parameter is the index position of the element, the second parameter is the original HTML content of the element, and If the value or the function return value is |
$.data() | Read or store data on specified elements. When storing data, if the value is Note: This method does not retrieve |
$.removeData() | Remove data stored on specified elements. Multiple keys can be separated by spaces, or represented by an array of multiple keys. When no keys are specified, all data on the element will be removed. |
.data() | Read or store data on elements in the current collection. When storing data, if the value is Note: The data retrieved by this method will include |
.removeData() | Remove data stored on elements in the current collection. Multiple keys can be separated by spaces, or represented by an array of multiple keys. When no keys are specified, all data on the elements will be removed. Note: This method only removes data set via the |
.css() | Get the CSS property value of the first element in the collection. Can also set CSS property values for all elements in the collection. The property value can be a string, number, or a callback function that returns a string or number. If the property value is a callback function, its first parameter is the index position of the element, the second parameter is the original CSS property value of the element, and If the property value or the callback function returns If the property value or callback function returns a number, Multiple CSS properties can also be set simultaneously by passing an object of key-value pairs. |
.width() | Get the width (in pixels) of the first element in the collection, excluding Can also set the width for all elements in the collection (excluding the width of The value can be a string with a unit, a number, or a callback function returning a string with a unit or a number. The first parameter of the callback function is the index position of the element, the second parameter is the original width value of the element, and If the value or the return value of the callback function is a number, If the value or the return value of the callback function is |
.height() | Get the height (in pixels) of the first element in the collection, excluding Can also set the height for all elements in the collection (excluding the height of The value can be a string with a unit, a number, or a callback function returning a string with a unit or a number. The first parameter of the callback function is the index position of the element, the second parameter is the original height value of the element, and If the value or the return value of the callback function is a number, If the value or the return value of the callback function is |
.innerWidth() | Get the width (in pixels) of the first element in the collection, including Can also set the width of all elements in the collection (including The value can be a string with a unit, a number, or a callback function returning a string with a unit or a number. The first parameter of the callback function is the index position of the element, the second parameter is the original width value of the element, and If the value or the return value of the callback function is a number, If the value or the return value of the callback function is |
.innerHeight() | Get the height (in pixels) of the first element in the collection, including Can also set the height of all elements in the collection (including The value can be a string with a unit, a number, or a callback function returning a string with a unit or a number. The first parameter of the callback function is the index position of the element, the second parameter is the original height value of the element, and If the value or the return value of the callback function is a number, If the value or the return value of the callback function is |
.outerWidth() | Get the width (in pixels) of the first element in the collection, including Can also set the width of all elements in the collection (including The first parameter can be a string with a unit, a number, or a callback function returning a string with a unit or a number. The first parameter of the callback function is the index position of the element, the second parameter is the original width of the element, and If the value or the return value of the callback function is a number, If the value or the return value of the callback function is |
.outerHeight() | Get the height (in pixels) of the first element in the collection, including Can also set the height of all elements in the collection (including The first parameter can be a string with a unit, a number, or a callback function returning a string with a unit or a number. The first parameter of the callback function is the index position of the element, the second parameter is the original height of the element, and If the value or the return value of the callback function is a number, If the value or the return value of the callback function is |
.hide() | Hide all elements in the collection. |
.show() | Show all elements in the collection. |
.toggle() | Toggle the display state of all elements in the collection. |
.offset() | Get the coordinates of the first element in the collection relative to the Can also set the coordinates of all elements in the collection relative to the The parameter is an object containing If the parameter is a callback function, the first parameter is the index position of the element, the second parameter is the original coordinates of the element, and If the values of |
.offsetParent() | Return the positioning parent of the first element in the collection — that is, the first ancestor element whose |
.position() | Get the offset of the first element in the collection relative to its parent element. |
.find() | Find specified descendant nodes in all elements of the current collection based on a CSS selector. |
.children() | Get the collection of direct child elements from all elements in the current collection. A CSS selector can be passed as a parameter to filter the child elements. |
.has() | Filter elements containing the specified child elements from all elements in the current collection. Parameters can be CSS selectors or DOM elements. |
.parent() | Get the collection of direct parent elements for all elements in the current collection. A CSS selector can be passed as a parameter to return only the collection of parent elements matching that parameter. |
.parents() | Get the collection of ancestor elements for all elements in the current collection. A CSS selector can be passed as a parameter to return only the collection of ancestor elements matching that parameter. |
.parentsUntil() | Get all parent elements of each element in the current collection until reaching an element matching the first parameter (matching element excluded). The first parameter can be a CSS selector, DOM element, or JQ object. An optional second parameter must be a CSS selector, indicating that only elements matching this parameter should be returned. If no parameters are specified, all ancestor elements will be matched, which is the same as |
.prev() | Get a collection of the previous sibling elements of all elements in the current collection. A CSS selector can be passed as a parameter to get only the collection of sibling elements matching that parameter. |
.prevAll() | Get a collection of all previous sibling elements of all elements in the current collection. A CSS selector can be passed as a parameter to get only the collection of sibling elements matching that parameter. |
.prevUntil() | Get all previous sibling elements of each element in the current collection until reaching an element matching the first parameter (matching element excluded). The first parameter can be a CSS selector, DOM element, or JQ object. An optional second parameter must be a CSS selector, indicating that only elements matching this parameter should be returned. |
.next() | Get a collection of the next sibling elements of all elements in the current collection. A CSS selector can be passed as a parameter to get only the collection of sibling elements matching that parameter. |
.nextAll() | Get a collection of all subsequent sibling elements of all elements in the current collection. A CSS selector can be passed as a parameter to get only the collection of sibling elements matching that parameter. |
.nextUntil() | Get all subsequent sibling elements of each element in the current collection until reaching an element matching the first parameter (matching element excluded). The first parameter can be a CSS selector, DOM element, or JQ object. An optional second parameter must be a CSS selector, indicating that only elements matching this parameter should be returned. |
.closest() | Match upwards from the current element level by level and return the first element matched. Parameters can be CSS selectors, DOM elements, or JQ objects. |
.siblings() | Get the sibling elements of each element in the current collection. A CSS selector can be passed as a parameter to get only sibling elements matching that parameter. |
.add() | Add elements to the current collection. Parameters can be HTML strings, CSS selectors, JQ objects, DOM elements, arrays of DOM elements, or NodeList. |
.empty() | Remove all child nodes from the current elements. |
.remove() | Remove elements in the current collection from the DOM. A CSS selector can be passed as a parameter to remove only the elements matching that parameter. |
.prepend() | Insert specified content before the inside of the elements in the current collection. Parameter types can be HTML strings, DOM elements, arrays of DOM elements, or JQ objects. Multiple parameters are supported. A callback function returning an HTML string, DOM element, array of DOM elements, or JQ object can also be passed. The first parameter is the index position of the current element, the second parameter is the original HTML of the element, and This method returns the original collection. |
.prependTo() | Prepend elements in the current collection to the inside of the specified elements. Parameters can be CSS selectors, HTML strings, DOM elements, arrays of DOM elements, or JQ objects. This method returns the original collection. |
.append() | Insert specified content at the end of the inside of the elements in the current collection. Parameter types can be HTML strings, DOM elements, arrays of DOM elements, or JQ objects. Multiple parameters are supported. A callback function returning an HTML string, DOM element, array of DOM elements, or JQ object can also be passed. The first parameter is the index position of the current element, the second parameter is the original HTML of the element, and This method returns the original collection. |
.appendTo() | Append elements in the current collection to the inside of the specified elements. Parameters can be CSS selectors, HTML strings, DOM elements, arrays of DOM elements, or JQ objects. This method returns the original collection. |
.after() | Insert specified content after the current collection elements as sibling nodes. Parameter types can be HTML strings, DOM elements, arrays of DOM elements, or JQ objects. Multiple parameters are supported. A callback function returning an HTML string, DOM element, array of DOM elements, or JQ object can also be passed. The first parameter is the index position of the current element, the second parameter is the original HTML of the element, and This method returns the original collection. |
.insertAfter() | Insert elements in the current collection after the target element as sibling elements. If the elements in the current collection already exist in the page, they will be moved instead of copied. If there are multiple targets, the elements in the current collection will be cloned and added after each target element. An HTML string, CSS selector, DOM element, array of DOM elements, or JQ object can be passed as a parameter to specify the target element. |
.before() | Insert specified content before the current collection elements as sibling nodes. Parameter types can be HTML strings, DOM elements, arrays of DOM elements, or JQ objects. Multiple parameters are supported. A callback function returning an HTML string, DOM element, array of DOM elements, or JQ object can also be passed. The first parameter is the index position of the current element, the second parameter is the original HTML of the element, and This method returns the original collection. |
.insertBefore() | Insert elements in the current collection before the target element as sibling elements. If the elements in the current collection already exist in the page, they will be moved instead of copied. If there are multiple targets, the elements in the current collection will be cloned and added after each target element. An HTML string, CSS selector, DOM element, array of DOM elements, or JQ object can be passed as a parameter to specify the target element. |
.replaceWith() | Replace elements in the current collection with the specified elements. Parameters can be HTML strings, DOM elements, arrays of DOM elements, or JQ objects. A callback function returning an HTML string, DOM element, array of DOM elements, or JQ object can also be passed. The first parameter is the index position of the current element, the second parameter is the original HTML of the element, and This method returns the original collection, i.e., the replaced collection. |
.replaceAll() | Replace specified elements with elements in the current collection. Parameters are CSS selectors, DOM elements, arrays of DOM elements, or JQ objects. This method returns the original collection, i.e., the collection of elements used for replacement. |
.clone() | Clone all elements in the collection via deep cloning. Deep clone all elements in the collection using the native |
.serializeArray() | Combine the values of form elements into an array of key-value pairs consisting of This method can operate on individual form elements or entire |
.serialize() | Serialize the values of form elements. |
.on() | Bind event handlers to specific events for each element in the collection. See the examples below for specific usage: |
.one() | Bind event handlers for specific events on each matching element, but the event will only trigger once. The usage of this method is the same as |
.off() | Unbind events for each element in the collection. See the examples below for specific usage: |
.trigger() | Trigger specified events. See the examples below for specific usage: |
$.ajaxSetup() | Set global configuration parameters for Ajax requests. See the AJAX Parameters below for the detailed list of parameters. |
$.ajax() | Send an AJAX request and return a Promise. See the AJAX Parameters below for the detailed list of parameters. |
.ajaxStart() | Global AJAX events. Execute a function when an AJAX request starts. |
.ajaxSuccess() | Global AJAX events. Execute a function when an AJAX request is successful. |
.ajaxError() | Global AJAX events. Execute a function when an AJAX request error occurs. |
.ajaxComplete() | Global AJAX events. Execute a function when an AJAX request is completed. |
| Param Name | Type | Default | Description |
|---|---|---|---|
url | String | URL of the current page. | The URL address for the request. |
method | String | GET | Request method. Includes: GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE |
data | any | '' | Data sent to the server. |
processData | Boolean | true | Whether to convert the passed-in data into a query string for sending. |
async | Boolean | true | Whether the request is asynchronous. |
cache | Boolean | true | Whether to read from the cache. Only valid for GET and HEAD requests. |
username | String | '' | Username for HTTP access authentication. |
password | String | '' | Password for HTTP access authentication. |
headers | Object | {} | Data added to Headers. This value can be overwritten in the Fields with string or |
xhrFields | Object | {} | Data set on the XMLHttpRequest object. |
statusCode | Object | {} | An object composed of HTTP status codes and functions. If the status code is between 200 and 299, or if it is 304, it indicates a successful request, and the function parameters are the same as those for the |
dataType | String | text | Type of data returned by the server. Includes: text, json |
contentType | String | application/x-www-form-urlencoded | Encoding type of the content. If false, Content-Type will not be set. |
timeout | Number | 0 | Request timeout (milliseconds). 0 means no timeout. |
global | Boolean | true | Whether to trigger global AJAX events. |
beforeSend | Function | Called before the request is sent. If it returns | |
success | Function | Called after the request is successful. | |
error | Function | Called when the request fails. | |
complete | Function | Called after the request is completed. |
Note: These methods only exist in the mdui framework; they are not available if you use the mdui.jq library directly.
.reflow() | Force a repaint of the current element. |
.transition() | Set the Can be a time value with or without a unit. If it has no unit, |
.transitionEnd() | Add a transitionend event callback to the current element. The parameter of the callback function is the |
.transform() | Set the |
.transformOrigin() | Set the |
.mutation() | Execute initialization functions registered within the current element and its children. |
$.showOverlay() | Create and show an overlay, returning the JQ object of the overlay layer. An integer parameter can be passed to represent the |
$.hideOverlay() | Hide the overlay layer. If |
$.lockScreen() | Lock the page to prevent scrolling. |
$.unlockScreen() | Unlock the page. If |
$.throttle() | Function throttling. Pass a function as a parameter; the first parameter is the function to execute, and the second parameter is the delay time in milliseconds. |
$.guid() | Generate a globally unique ID. A parameter can be passed. If the guid corresponding to that parameter value does not exist, a new guid is generated and returned; if it already exists, the existing guid is returned directly. |