douren8379 2013-04-21 21:35
浏览 51
已采纳

简单的jquery php数学实时更新文本字段

I have been working on this since 11am EST :/

Unable to find out where I am wrong, my java/jquery is non existent (trying to pick it up)

What I am trying to do is calculate litecoin's per day based on a few variables.

LTC/day = (50) * (24) * (24) ) / (User_hash/net_hash)

IE:

(block * 24 * 24) / (mhs / $ltcdiff) = LTC/day or total text field

here is the code, any light shed on it would be great, I am trying to get it to update live as you type the mhs rate into that field.

<? 
$jsonurl = "http://www.litehosting.org/API/LTC/litecoin.php";
$json = file_get_contents($jsonurl,0,null,null);
$data = json_decode($json, true);
$dat =  $data['return']['getinfo'];
$ltcdiff = $dat['difficulty'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
$('input').keyup(function(){
var mhs = $('input[name="hash"]').val(),
diff = $('input[name="diff"]').val(),
block = ('50'),
result;

if (mhs != "" && diff != "" && block != ""){
    result = ((block*24) * (24)) / ((mhs) / (diff));
    $('input[name="total"]').val(result);
}
});
</script>
</head>
<body>
<h1>LTC example</h1>
<form name="myForm">
<P> mh/s: </P>
<input type="text" name="hash"><BR>
<P> diff: </P>
<input type="text" name="diff" value="<? echo $ltcdiff;?>"><BR>
<P> total coin: </P>
<input type="text" name="total">
<BR>
</form>
</body>
</html>

The php code can be ignored, it's pulling the right data, it seems to be just the javascript.

  • 写回答

1条回答 默认 最新

  • dsbezji539113152 2013-04-21 21:51
    关注

    You need to reference JQuery to use JQuery functions. Also, make sure your JavaScript is rendered after the element you're targeting with JQuery:

    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
            <title>Untitled Document</title>
        </head>
        <body>
            <h1>LTC example</h1>
            <form name="myForm">
                <P> mh/s: </P>
                <input type="text" name="hash"><BR>
                <P> diff: </P>
                <input type="text" name="diff" value="<? echo $ltcdiff;?>"><BR>
                <P> total coin: </P>
                <input type="text" name="total">
                <BR>
            </form>
            <script type="text/javascript">
            $('input').keyup(function(){
                var mhs = $('input[name="hash"]').val(),
                diff = $('input[name="diff"]').val(),
                block = ('50'),
                result;
    
                if (mhs != "" && diff != "" && block != ""){
                    result = ((block*24) * (24)) / ((mhs) / (diff));
                    $('input[name="total"]').val(result);
                }
            });
            </script>
        </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?