<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<Body>
<Input id = "text1" name = "text1" value = "D:/mydesktop/Ruby/baby/OK">
</Body>
<Script language = "JavaScript">
VaR STR = Document. getelementbyid ("text1"). value;
Alert (STR );
STR = Str. Replace (///g ,'////');
Alert (STR );
</SCRIPT>
</Html>
The above instancesSource codeThere are two key points here
:
1. Replace replaces all matching characters Replace (S1, S2). By default, replace the first matching character. If you replace all the matching characters, use the subexpression in the mode. For example: /mode subexpression/g, where G can replace multiple places.
2. replace "/" with "//", which means "/". The key is "//", special characters in Javascript must be escaped. Therefore, "/"-corresponds to-"//", "//"-corresponds to-"//",