开发者的天空

 

 

搜索
开发者的天空 论坛 web前端技术 Jquery写入txt的一个计算器
查看: 813|回复: 0
go

[HTML] Jquery写入txt的一个计算器

Rank: 1

发表于 2011-9-27 01:04 |显示全部帖子

   
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>无标题文档</title>
  6. <script type="text/javascript" src="jquery-1.4.2.js" ></script>
  7. <script type="text/javascript">
  8.         $(document).ready(
  9.                 function (){

  10.                         $("#next").hide();
  11.                         $("#fx").click(function(){

  12.                                 if(!/^[0-9]+.?[0-9]*$/.test($("#price").val()) || !/^[0-9]+.?[0-9]*$/.test($("#year").val()) || !/^[0-9]+.?[0-9]*$/.test($("#rate").val()) ){
  13.                                         alert("请输入正确的数字");
  14.                                 }
  15.                                 else{
  16.                                         var price=parseFloat($("#price").val());
  17.                                         var rate=parseFloat($("#rate").val());
  18.                                         var year=parseFloat($("#year").val());
  19.                                         var result=rate/100+1;
  20.                                         var sum;
  21.                                                 for(var i=0;i<year-1;i++){
  22.                                                         result=result*(rate/100+1);
  23.                                                 }
  24.                
  25.                                         result=result*price;
  26.                                         sum=(result-price)/3;
  27.                        
  28.                                         $("#reprice").val(result.toFixed());
  29.                                         $("#rerate").val(sum.toFixed());
  30.                

  31.                                        

  32.                                         }
  33.                         });


  34.                         $("#reset").click(function(){
  35.                                                                           
  36.                                 $("#price").attr("value","");
  37.                                 $("#rate").attr("value","");
  38.                                 $("#year").attr("value","");
  39.                                 $("#reprice").attr("value","");
  40.                                 $("#rerate").attr("value","");
  41.                                
  42.                         });

  43.                         $("#price").blur(function(){
  44.                        
  45.                                 if(!/^[0-9]+.?[0-9]*$/.test(this.value)){
  46.                                        
  47.                                         $(this).next().html("请输入有效的数字");
  48.                                
  49.                                 }
  50.                                 else{
  51.                                         $(this).parent().next().html("");
  52.                                 }
  53.                        
  54.                         });
  55.                        
  56.                         $("#rate").blur(function(){
  57.                        
  58.                                 if(!/^[0-9]+.?[0-9]*$/.test(this.value)){
  59.                                        
  60.                                         $(this).parent().next().html("请输入有效的数字");
  61.                                
  62.                                 }
  63.                                 else{
  64.                                         $(this).parent().next().html("");
  65.                                 }
  66.                        
  67.                         });
  68.                         $("#year").blur(function(){
  69.                        
  70.                                 if(!/^[0-9]+.?[0-9]*$/.test(this.value)){
  71.                                        
  72.                                         $(this).parent().next().html("请输入有效的数字");
  73.                                        
  74.                                
  75.                                 }
  76.                                 else{
  77.                                         $(this).parent().next().html("");
  78.                                 }
  79.                        
  80.                         });
  81.                         $("#telButton").click(function(){
  82.                                                                                
  83.                                 if(/^[0-9]+.?[0-9]*$/.test($("#tel1").val()) &amp;&amp; $("#tel1").val().length==11){
  84.                                         var rul =window.location.href;
  85.                                         var src=rul.substring(0,rul.length-9);
  86.                                         src=src.replace("file:///","");
  87.                                         var str=new Array();
  88.                                         str=src.split("/");
  89.                                         var lastUrl="";
  90.                                         for(var i=0;i<str.length;i++){
  91.                                                 lastUrl=lastUrl+str[i]+"\\"+"\\";
  92.                                         }
  93.                                         alert(lastUrl);

  94.                                          var   fso   =   new   ActiveXObject( "Scripting.FileSystemObject");
  95.                                         if(fso.FileExists(lastUrl+"testfile.txt ") ){
  96.                                                 var a=fso.OpenTextFile(lastUrl+"testfile.txt ",8,true);
  97.                                                 a.WriteLine($("#tel1").val());
  98.                                                 a.Close();
  99.                                         }
  100.                                         else{
  101.                                                 var   a   =   fso.CreateTextFile( lastUrl+"testfile.txt ",   true);
  102.                                                 a.WriteLine($("#tel1").val());
  103.                                                 a.Close();
  104.                                         }                                       
  105.                                         $("#next").show();
  106.                                         $("#before").hide();       
  107.                                 }
  108.                                 else{
  109.                                         alert("请输入正确的手机号码");
  110.                                 }
  111.                         });
  112.                        
  113.                 }
  114.         );
  115.   </script>
  116. </head>
  117. <body>
  118. <div id="next">

  119. </div>
  120. </body>
  121. </html>
复制代码



ActiveX只对ie支持效果好点,其他浏览器都不支持- -。
存入本地的文件路径需要为英文。非专业js,只提供思路,不做深入了撒
  
你需要登录后才可以回帖 登录 | 注册

Archiver|开发者的天空

GMT+8, 2012-5-21 05:02

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.