Home > Article > Web Front-end > How to delete the first character of a string in jquery
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)".
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.
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.
In the test.html file, use the button tag to create a button with the button name "Delete the first character".
In the test.html file, bind the onclick event to the button button. When the button is clicked, execute the myfun() function.
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.
Open the test.html file in the browser, enter the string, click the button to view the results.
[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!