0

从美国东部时间上午 11 点开始,我一直在研究这个:/

无法找出我错了,我的 java/jquery 不存在(试图拿起它)

我想做的是根据几个变量计算莱特币每天的数量。

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

IE:

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

这是代码,任何关于它的说明都会很棒,我正试图让它在您在该字段中输入 mhs 速率时实时更新。

<? 
$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>

可以忽略 php 代码,它正在提取正确的数据,它似乎只是 javascript。

4

1 回答 1

1

您需要引用 JQuery 才能使用 JQuery 函数。此外,请确保您的 JavaScript 在您使用 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>
于 2013-04-21T21:51:27.880 回答