php如何为onblur函数动态创建文本框

时间:2017-04-14 06:47:40

标签: php

我从数据库中获取详细信息并在同一页面中显示,我必须更新权重列的模糊值。我的问题是onblur无法正常工作。请查看下面的模糊功能代码,请帮忙。 :)

<!DOCTYPE html>
<html>
<head>
    <?php 
        include "dbconfig.php";
        include "yrsetup.php";      
        $ttable='lot'.$yr;
    ?>
    <style>

    </style>
 <script type="text/javascript" src="jquery-1.6.1.js"></script>
 <script>
    $(document).ready(function(){
        $("#tdate").change(function(){
        var tdate = $(this).val();
            $.post("lotno.php",
                     {
                         tdate: tdate
                     },
                     function(data,status){
                         $("#target-content").html(data);
                         //alert("Data: " + data + "\nStatus: " + status);
            });         
        });

        $("#target-content").change(function(){
        var tlotno = $(this).val();
        var tdate = $("#tdate").val();
//alert(tlotno);        
        $.post("getdet.php",
                     {
                         tlotno: tlotno,
                         tdate: tdate
                     },
                     function(data,status){
                         $("#gtdet").html(data);
                         //alert("Data: " + data + "\nStatus: " + status);
            });         
        });
///////////////////

////////////////////////////////
    $(".bweight").blur(function(){
    var text = $(this).val();
    alert(text);
/*  id = $(this).closest('.mob').attr('data-id');
            $.post("mobupdate.php",
                 {
                     id: id,
                     text: text
                 },
                 function(data,status){
                        // $("#target-content").html(data);
                        //  alert("Data: " + data + "\nStatus: " + status);
                 });            
 */ 
 });

});


</script> 

</head>
    <body>


enter code here

    <form>
            <table>
                <tr>
                    <td>
                        Select Date:<input type="date" id='tdate' name='tdate' >
                    </td>
                    <td>
                        Select A/P/C:
                            <select name='apcslct' class='apcslct'>
                                <option>A</option>      
                                <option>P</option>      
                                <option>C</option>                                      
                            </select>
                    </td>

                    <td>
                        Select LotNo:
                        <select id="target-content"></select>
                    </td>
                </tr>               
            </table>
            <div id="gtdet">

            </div>  
        </form>

    </body>
</html>



getdet.php

<?php 
    include "dbconfig.php";
    include "yrsetup.php";      
    $ttable='lot'.$yr;

    $tdate1=$_POST['tdate'];
    //$tdate1=date('d-m-Y');
    $tdate = date('Y-m-d', strtotime($tdate1));

    $tlotno=$_POST['tlotno'];

    //echo $tdate;
        $sql="SELECT lotno,asmsoc,$ttable.acno,CONCAT(assami.frst,' ',assami.send,' ',assami.thrd,' ',assami.vilg) AS ename,
        $ttable.sacno,sno,apcd,allcodes.name AS iname,nobgs,kqty,kore,$ttable.rate,purno,pur.`send` as purnm,nqty AS weight 
        FROM $ttable 
        LEFT JOIN assami ON assami.mrk IS NULL AND  $ttable.acno=assami.acno
        LEFT JOIN allcodes ON allcodes.sw='IT'  AND $ttable.`apcd`=allcodes.cd
        LEFT JOIN pur ON pur.mrk IS NULL AND $ttable.purno=pur.`acno`
        WHERE $ttable.mrk IS NULL AND  date1='$tdate' AND atoz='$tlotno' AND asmsoc='A' UNION ALL
        SELECT lotno,asmsoc,$ttable.acno,society.ename AS ename,
        $ttable.sacno,sno,apcd,allcodes.name AS iname,nobgs,kqty,kore,$ttable.rate,purno,pur.`send` as purnm,nqty AS weight 
        FROM $ttable 
        LEFT JOIN society ON society.mrk IS NULL AND  $ttable.acno=society.acno
        LEFT JOIN allcodes ON allcodes.sw='IT'  AND $ttable.`apcd`=allcodes.cd
        LEFT JOIN pur ON pur.mrk IS NULL AND $ttable.purno=pur.`acno`
        WHERE $ttable.mrk IS NULL AND  date1='$tdate' AND atoz='$tlotno' AND asmsoc='S' ORDER BY lotno ";

    $res=mysqli_query($mysqli,$sql);
    if($res == FALSE) {
       die(mysqli_error($mysqli)); // TODO: better error handling
    }else{
        //printf("Select returned %d rows.\n", $res->num_rows);
    }
    $row=mysqli_fetch_array($res);
?>
<table border="1px">
<tr>
    <th>
        LOtno
    </th>
    <th>
        A/S
    </th>
    <th>
        Acno
    </th>

    <th>
        Name
    </th>
    <th>
        SubNo
    </th>
    <th>
        Sno
    </th>
    <th>
        Icode
    </th>
    <th>
        Item
    </th>
    <th>
        Bags
    </th>
    <th>
        Kqty
    </th>
    <th>
        Kore
    </th>
    <th>
        Rate
    </th>
    <th>
        PCode
    </th>
    <th>
        PName
    </th>
    <th>
        Weight
    </th>

</tr>
<?php
    do{
?>
<tr>
    <td>
        <input type="text" disabled="disabled" name="lotno" class="lotno" value="<?php echo $row['lotno']; ?>" data-id="<?php echo $row['lotno'];?>" style="width:30PX" >
    </td>
    <td>
        <?php echo $row['asmsoc'];?>
    </td>
    <td>
        <?php echo $row['acno'];?>
    </td>
    <td>
        <?php echo $row['ename'];?>
    </td>
    <td>
        <?php echo $row['sacno'];?>     
    </td>
    <td>
        <?php echo $row['sno'];?>
    </td>
    <td>
        <?php echo $row['apcd'];?>
    </td>
    <td>
        <?php echo $row['iname'];?>
    </td>
    <td>
        <?php echo $row['nobgs'];?>
    </td>
    <td>
        <?php echo $row['kqty'];?>
    </td>
    <td>
        <?php echo $row['kore'];?>
    </td>
    <td>
        <?php echo $row['rate'];?>
    </td>
    <td>
        <?php echo $row['purno'];?>
    </td>
    <td>
        <?php echo $row['purnm'];?>
    </td>
        <?php if ($row['weight']>0){ ?>
            <td>
                <input type="number" class="bweight" value="<?php echo $row['weight'];?>" style="border:none;" onblur="blr(this);" >
            </td>
        <?php } else { ?>
        <td >
            <input type="number" class="bweight" style="border:none;" onblur="blr(this);">
        </td>
        <?php } ?>
    </td>   
    </td>
</tr>   
<?php
    }while ($row=mysqli_fetch_array($res)); 
?>  
</table>

2 个答案:

答案 0 :(得分:1)

您使用的是jQuery 1.6。 on()函数尚不可用。请改用live():http://api.jquery.com/live/

答案 1 :(得分:0)

尝试使用升级版jQuery,即mongoexport内的jQuery 1.7 + jQuery On或者您可以使用$(document).ready代替live

on