Replace () is used to replace other characters with some characters in a string, or replace a substring that matches a regular expression.
The lastIndexOf () method searches from the back and forward of the specified string, excluding the selected string and starts counting from 1.
Substring () is used to extract characters that are intermediary between two pointer subscripts, including the two strings themselves.
Instance:
// Clothes color switch var $ color_img = $ (". color_change ul li img "); $ color_img.bind (" click ", function () {$ (this ). addClass ("hover "). parent (). siblings (). find ("img "). removeClass ("hover"); var colorSrc = $ (this ). attr ("src"); var colori = colorSrc. lastIndexOf (". "); var colorUnit = colorSrc. substring (colori); colorcolorSrc. substring (0, colori); var colorSrc_big = colorSrc + "_ one" + "_ big" + colorUnit; var colorSrc_small = colorSrc + "_ o Ne "+" _ small "+ colorUnit; $ (" # bigImg "). attr ({"src": colorSrc_small}); $ ("# thickImg "). attr ("href", colorSrc_big); var alt = $ (this ). attr ("alt"); $ (". color_change strong "). text (alt); var newColor colorSrc. substring (15, colori) // use the substring () method to find the corresponding color word in colorSrc // var newColorcolorSrc. replace ("images/pro_img/", ""); // The replace () method is used to replace other characters with some characters in the string, or replace a substring that matches the regular expression. // Replace () can be used in the original file. I don't know how to use it here, so it is replaced by sbustring. $ (". ImgList li "). hide (); $ (". imgList "). find (". imgList _ "+ newColorSrc ). show (); // used to solve the bug. After switching the color, enlarge the image and display the original image. $ (". ImgList "). find (". imgList _ "+ newColorSrc ). eq (0 ). find (""). click ();}). hover (function () {$ (this ). addClass ("hover1") ;}, function () {$ (this ). removeClass ("hover1 ");});