Javascript无法读取输入值

时间:2016-07-21 03:23:41

标签: javascript php jquery html input

我的javascript没有读取我的输入值。第一个问题是因为输入值已与自动加载div集成。如果我使用纯输入值,它可以工作,但如果输入与自动加载div集成,它将停止工作。

这是我的PHP代码:

<form method="post" action="" target="_parent">
        <h4 style="color: grey; font-size: 30px; margin: auto;"><b>Jumlah Diterima</b></h4>
        <div class="input-control">
                <input type="text" name="amt" id="amt" style="width:300px; font-size: 30px; height: 50px; font-weight: bold;  margin: auto; color:grey;">
        </div><br/><br/><br/>
        <h4 style="color: grey; font-size: 30px; margin: auto;"><b>Jumlah Tagihan</b></h4><br><br>
        <h4 style="color: grey; font-size: 30px; margin: auto;"><b>Rp. <?php echo $nominal; ?>,-</b></h4>
        <input type="text" id="nominal" name="nominal" value="1000">
        <br><br><br><br><br>
<input type="submit" value="Selesai" style="background: #1ba1e2; border-color: #1ba1e2; height: 70px; font-weight: bold;  margin-left: 150px; width:280px; font-size: 30px;" class="button primary" />
        </div>

这是我的javascript

<script type="text/javascript" src="http://code.jquery.com/jquery-3.1.0.slim.js"></script>
<script type="text/javascript">
 var $jq = jQuery.noConflict();
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script>
$jq(function() {
    var money = 7000;

    $jq("#nominal").on("change keyup", function() {
        var input = $jq(this);

        // remove possible existing message
        if( input.next().is("form") )
            input.next().remove();

        // show message
        if( input.val() > money )
            input.after("<form method=\"post\" action=\"\"><input type=\"submit\" name=\"yes\" value=\"Yes\"><input type=\"submit\" name=\"no\" value=\"No\"></form>");
    });
});
</script>
<script>
function loadValue5() {
    $.ajax({
        method: 'GET',
        url: 'grab_count_old.php',
        success: function(responseText) {
            $('#amt').fadeOut('fast', function () {
                $('#amt').val(responseText).fadeIn('fast', function() {
                    setTimeout(loadValue5, 100);
                });
            });
        }
    });
}
loadValue5();
</script>

这是我的grab_count.php(自动加载)

<?php
include("../config/db_function.php");
db_function();

mysql_select_db("testpy") or die(mysql_error());
$result = mysql_query("SELECT * FROM datapy ORDER BY No DESC LIMIT 0,1")
or die(mysql_error());
        while($row = mysql_fetch_array( $result )) {
           echo $row['nilai_1'];
        }

?>

在某些情况下,如果使用ID(纯输入)更改javascript中的#nominal,它会起作用,但如果我使用#amt更改(使用自动加载输入)则无法正常工作。任何帮助将不胜感激,我不知道如何解决它。

0 个答案:

没有答案