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 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭