- <script language="javascript">
- var strM = "javascript is a good script language";
- //在此我想将字母a替换成字母A
- alert(strM.replace("a","A"));
- </script>
- <script language="javascript">
- var strM = "javascript is a good script language";
- //在此我想将字母a替换成字母A
- alert(strM.replace(/a/,"A"));
- </script>
- <script language="javascript">
- var strM = "javascript is a good script language";
- //在此将字母a全部替换成字母A
- alert(strM.replace(/a/g,"A"));
- </script>
- <script language="javascript">
- var strM = "javascript is a good script language";
- alert(strM.replace(/(javascript)/s*(is)/g,"$1 $2 fun. it $2"));
- </script>
- <script language="javascript">
- var strM = "javascript is a good script language";
- function change(word)
- {
- return word.indexOf(0).toUpperCase()+word.substring(1);
- }
- alert(strM.replace(//b/w+/b/g,change));
- </script>
- <script language="javascript">
- var strM = "javascript is a good script language";
- function change(word)
- {
- var result = word.match(/(/w)/g);
- if ( result )
- {
- var str = "";
- for ( var i=result.length-1; i>=0; i-- )
- {
- str += result;
- }
- return str;
- }
- else
- {
- return "null";
- }
- }
- alert(strM.replace(//b(/w)+/b/g,change));
- </script>
新闻热点
疑难解答