In js replace method is used to complete the conversion of a character
- 2020-03-30 03:44:54
- OfStack
var str = " The word [1990]12 No. ";
How to put a backslash before the "[" and"] "in a variable,
STR = "country word \[1990\] no. 12 ";
<script language="javascript" type="text/javascript">
var str = " The word [1990]12 No. ";
str=str.replace(/[/g,'\[');
str=str.replace(/]/g,'\]');
document.write(str);
</script>