<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head> <body><p>输入数字:<input type="text" class="inp1"></p><button>转换</button><p>转换成货币为:<input type="text" class="inp2" disabled="disabled"></p> </body><script src="../jquery-1.11.3.js"></script><script> $(‘button‘).click(function(){ $(‘.inp2‘).val(zhuanhuan($(‘.inp1‘).val())) }); function zhuanhuan(huoBi){ if(huoBi.indexOf(‘.‘)<0){ huoBi=huoBi+‘.‘ } var huobibrr=huoBi.split(‘.‘)[0]; var huoBiarr=huoBi.split(‘.‘)[1]; if(huoBiarr.length==0){ huoBiarr=‘00‘ }else if(huoBiarr.length==1){ huoBiarr=huoBiarr+‘0‘ } huoBi=huobibrr+‘.‘+huoBiarr; return huoBi }</script></html>
时间: 2024-10-12 08:48:24