字符串截取数字和点击radio显示不同内容
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>test</title> <script type="text/javascript"> function payTypeClick(){ var gameMoneyActStr = document.getElementById("gameMoneyAct").innerHTML; var dummycurStr= gameMoneyActStr.replace(/^[^\d]*(\d+)[^\d]*$/, "$1"); //字符串中截取数字 if(document.getElementById("payTypeGame").checked){ document.getElementById('gameMoneyAct').innerHTML=dummycurStr+"万点游戏币"; } else{ document.getElementById('gameMoneyAct').innerHTML=dummycurStr+"个金币"; } } </script> </head> <body> <table id="rl"> <tr> <td><label>全游戏币充值</label> <input id="payTypeGame" class="radioItem" checked="checked" name="rl$tt" type="radio" value="1" onClick="payTypeClick();"/> <label>全金币充值</label> <input id="payTypeGold" class="radioItem" name="rl$tt" type="radio" value="2" onClick="payTypeClick();"/></td> </tr> </table> <div id="gameMoneyAct">40万点游戏币</div> </body> </html>