Home >Web Front-end >Front-end Q&A >What is the usage of substr function in jquery
In jquery, the substr function is used to intercept a substring of a specified number of characters starting from the specified subscript of a string. This function supports two parameters. The first parameter specifies the starting subscript for interception. The two parameters specify the number of characters; the syntax is "string object.substr(start,length)".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, the substr function is used to intercept a specified number of characters starting from the specified subscript of a string. This intercepted character can be called a "substring" or "substring". Its syntax The format is as follows:
stringObject.substr(start,length)
Description | |
---|---|
start | Required. The starting index of the substring to be extracted. Must be a numeric value. If negative, this parameter declares the position from the end of the string. That is, -1 refers to the last character in the string, -2 refers to the second to last character, and so on.|
length | Optional. The number of characters in the substring. Must be a numeric value. If this parameter is omitted, the string from the beginning to the end ofstringObject is returned. |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { var text=$("p").text(); console.log(text.substr(5,6)); }); </script> </head> <body> <p>Hello world!</p> </body> </html>[Recommended learning:
jQuery video tutorial、web front-end】
The above is the detailed content of What is the usage of substr function in jquery. For more information, please follow other related articles on the PHP Chinese website!