Home  >  Article  >  Web Front-end  >  How to delete the first character of a string in jquery

How to delete the first character of a string in jquery

青灯夜游
青灯夜游Original
2022-03-10 17:43:423750browse

Method to delete the first character of a string: 1. Use the "$(selector).val()" statement to obtain the string content in the element; 2. Use the substr() method to intercept the string , and then delete the first character in the string, the syntax is "string content.substr(1, string length)".

How to delete the first character of a string in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, you can use the substr() method to intercept the string and delete the first character in the string.

Example:

In the test.html file, within the p tag, use the input tag to create a string input box to specify the string to be operated on.

How to delete the first character of a string in jquery

In the test.html file, set the id of the input tag to myinput, which is mainly used to obtain the input object through this id below.

How to delete the first character of a string in jquery

In the test.html file, use the button tag to create a button with the button name "Delete the first character".

How to delete the first character of a string in jquery

In the test.html file, bind the onclick event to the button button. When the button is clicked, execute the myfun() function.

How to delete the first character of a string in jquery

In the js tag, create the myfun() function. Within the function, obtain the input object through id (myinput), and use the val() method to obtain the input string. Then use the substr() function to intercept starting from the second character, and finally, use the alert() method to output the intercepted string.

How to delete the first character of a string in jquery

Open the test.html file in the browser, enter the string, click the button to view the results.

How to delete the first character of a string in jquery

[Recommended learning: jQuery video tutorial, web front-end video

The above is the detailed content of How to delete the first character of a string in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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