标签:ace cli ber charset ++ back title set console
这个纯粹是给自己留做备份用的,股票涨停有一个计算公式,但是为了自己方便查看股票涨了多少钱,还是决定自己写了一个
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>计算涨停</title> <style type="text/css"> input{ width: 160px; height: 26px; } #calc{ width: 50px; height: 25px; } </style> </head> <body> 成本价:<input type="text" placeholder="成本价" id="cost" value="8.34"> 当前价格:<input type="text" placeholder="当前价格" id="price" value="7.37"> 持有股数:<input type="text" placeholder="持有股数" id="capt" value="4000"> 涨停次数:<input type="text" placeholder="涨停次数" id="number" value="1"> <input type="button" value="计算" id="calc"> <div id="txt"> </div> <script type="text/javascript"> window.onload = function(){ var cost = document.getElementById(‘cost‘); // 成本价 var price = document.getElementById(‘price‘); // 当前价 var capt = document.getElementById(‘capt‘); // 持股数 var number = document.getElementById(‘number‘); // 涨停次数 var calc = document.getElementById(‘calc‘); var txt = document.getElementById(‘txt‘); calc.onclick = function(){ var cost_val = parseFloat( cost.value ); // 成本价 var price_val = parseFloat( price.value ); // 当前价 var capt_val = parseFloat( capt.value ); // 持股数 var number_val = parseFloat( number.value );// 涨停次数 var new_price, pri, totle_capt, profit; var htm = ‘‘; for (var i = 0; i < number_val; i++) { new_price = parseFloat( ( price_val / 10 ).toFixed(2) ); // 上涨价格 pri = parseFloat( ( price_val+new_price ).toFixed(2) ); // 总价 totle_capt = Math.round(pri * capt_val); // 总金额 profit = totle_capt - cost_val * capt_val; // 利润 htm += ‘<p>‘+(i+1)+‘次涨停后,价格为:‘+pri+‘<br>‘+‘总金额为:‘+totle_capt+‘<br>‘ + ‘利润为:‘ + profit+‘</p>‘; //console.log(new_price, pri, totle_capt, profit, htm); price_val = pri; }; txt.innerHTML = htm; }; }; </script> </body> </html>
标签:ace cli ber charset ++ back title set console
原文地址:https://www.cnblogs.com/carol1987/p/10218397.html