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

简单jquery php数学实时更新文本字段,php,javascript,jquery,html,Php,Javascript,Jquery,Html,我从美国东部时间上午11点就开始做这个:/ 无法找出我的错误所在,我的java/jquery不存在(正在尝试获取) 我想做的是根据几个变量计算litecoin每天的收入 LTC/day = (50) * (24) * (24) ) / (User_hash/net_hash) 即: 这是代码,任何关于它的光照都会很好,我试图让它在你将mhs速率输入该字段时进行实时更新 <? $jsonurl = "http://www.litehosting.org/API/LTC/litecoin.

我从美国东部时间上午11点就开始做这个:/

无法找出我的错误所在,我的java/jquery不存在(正在尝试获取)

我想做的是根据几个变量计算litecoin每天的收入

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

这是代码,任何关于它的光照都会很好,我试图让它在你将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>

无标题文件
$('input').keyup(函数(){
var mhs=$('input[name=“hash”]”)。val(),
diff=$('input[name=“diff”]”)。val(),
块=('50'),
结果;
如果(mhs!=“”&&diff!=“”&&block!=“”){
结果=((区块*24)*(24))/((mhs)/(差异));
$('input[name=“total”]).val(结果);
}
});
LTC示例

mh/s:


差异:


您需要引用JQuery来使用JQuery函数。另外,请确保在使用JQuery针对的元素之后呈现JavaScript:

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

无标题文件
LTC示例

mh/s:


差异:

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