javascript字串反轉+字串全部替換函數+input text元件取值/填值+按鈕事件範例
javascript字串反轉+字串全部替換函數+input text元件取值/填值+按鈕事件範例
資料來源:http://ygtw.blogspot.tw/2012/07/javascript-replace.html
https://www.w3cplus.com/javascript/how-to-reverse-a-string-in-javascript-in-different-ways.html
<html> <head> <title></title> <script> function reverseString(str)//字串反轉~https://www.w3cplus.com/javascript/how-to-reverse-a-string-in-javascript-in-different-ways.html { return str.split(“”).reverse().join(“”); } function replaceAll(txt, replace, with_this)//字串全部替換~http://ygtw.blogspot.tw/2012/07/javascript-replace.html { return txt.replace(new RegExp(replace, ‘g’),with_this); } function Calculate()// { var data=reverseString(document.getElementById(“in”).value); document.getElementById(“ou”).value=replaceAll (data,”j”,”a”); } </script> </head> <body> <font size=”+3″> input data: <input type=”text” style=”font-size:20px” size=”150″ id=”in”><br><br> output data: <input type=”text” style=”font-size:20px” size=”150″ id=”ou”><br><br> <button style=”font-size:20px” onclick=”Calculate()”>Run</button> </font> </body> </html> |