【问题标题】:Input box field value not display in json format输入框字段值不以json格式显示
【发布时间】:2016-08-28 02:29:17
【问题描述】:
<?php
echo "<table  id='example-table' class='table table-bordered table table-hover'>";
echo "<thead><tr class='main-head'>";
echo "<th>S.N.</th>";
echo "<th>Acode</th>";
echo "<th>Aname</th>";
echo "<th>{$lyp_1}</th>";
echo "<th>{$lyp_2}</th>";
echo"<th>Suply</th>";
echo "<th>Sum</th>";
echo "<th>Amount</th>";
echo "</tr></thead>";

$classcode = 'C' . $count;
//$idcode  = $nt[0];
//$classcode = 'C' . $idcounter;
//$classamt  = 'A' .  $idcounter;

$count=1;
while ($row = mysql_fetch_array($res_final)) {
    if($row[5]== 's') {
        $row4_info = "";

        if (($row[4]== 'y')&& ($row[5]!= 's')) {
            $row4_info = "<input type='text' id='{$row[0]}' class='A{$count}' value=''>";
        }

        $row5_info = "";

        if ($row[5]== 's') {
            $row5_info = "<input type='text' id='{$row[0]}' class='A{$count}' value='' disabled='disabled'>";
        }

        echo "<tr> <td>". $sn = $startpoint + $count . "</td>
              <td class='C{$count}'>"  .$row[0] ."</td>
              <td >" . $row[1] . "</td>
              <td>" . $row[2] . "</td>
              <td>" . $row[3] . "</td>
              <td class='warning'>" . $row[4] . "</td>
              <td class='warning'>" . $row[5] . "</td>
              <td>" .$row4_info.$row5_info."</td></tr>";
    } 
    else {
        echo "<tr><td>" . $sn = $startpoint + $count . 
              "</td><td class='C{$count}'>"  .$row[0] ."</td>
              <td>" . $row[1] . "</td>
              <td>" . $row[2] . "</td>
              <td>" . $row[3] . "</td>
              <td>" . $row[4] . "</td>
              <td>" . $row[5] . "</td>
              <td>" . "<input type='text' id='{$row[0]}'
              class='A{$count}' value=''  />" . "</td></tr>";
    }

    $count = $count +1;
}

echo "</table>";
echo "<button style='margin-left:30px' id='save' class='button      btn-submit btn btn-primary' name='save'>Save</button>";
?>

<html xmlns="http://www.w3.org/1999/xhtml">
    <script src="js/jquery.tabletojson.min.js" type="text/javascript"></script>
    <script src="js/jquery-2.2.3.js" type="text/javascript"></script>
    <head>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#save').click( function() {
                    var table = $('#example-table').tableToJSON();
                    console.log(table);
                    alert(JSON.stringify(table));
                });
            });

当我单击保存按钮时,我想在 json 中获取所有表值,它们在警报框中显示所有值。输入文本框值未在 json 中显示。我该如何解决这个问题,您可以在下面的链接中看到图像 http://www.aventissoft.net/deve/json/json.png

【问题讨论】:

    标签: php jquery mysql json


    【解决方案1】:

    更新你的 while 循环:

    while ($row = mysql_fetch_array($res_final)) {
        if($row[5]== 's') {
            $row4_info = "";
    
            if (($row[4]== 'y')&& ($row[5]!= 's')) {
                $row4_info = "<input type='text' id='".{$row[0]}."' class='A{$count}' value=''>";
            }
    
            $row5_info = "";
    
            if ($row[5]== 's') {
                $row5_info = "<input type='text' id='".{$row[0]}."' class='A{$count}' value='' disabled='disabled'>";
            }
    
            echo "<tr> <td>". $sn = $startpoint + $count . "</td>
                  <td class='C{$count}'>"  .$row[0] ."</td>
                  <td >" . $row[1] . "</td>
                  <td>" . $row[2] . "</td>
                  <td>" . $row[3] . "</td>
                  <td class='warning'>" . $row[4] . "</td>
                  <td class='warning'>" . $row[5] . "</td>
                  <td>" .$row4_info.$row5_info."</td></tr>";
        } 
        else {
            echo "<tr><td>" . $sn = $startpoint + $count . 
                  "</td><td class='C{$count}'>"  .$row[0] ."</td>
                  <td>" . $row[1] . "</td>
                  <td>" . $row[2] . "</td>
                  <td>" . $row[3] . "</td>
                  <td>" . $row[4] . "</td>
                  <td>" . $row[5] . "</td>
                  <td>" . "<input type='text' id='{$row[0]}'
                  class='A{$count}' value=''  />" . "</td></tr>";
        }
    
        $count = $count +1;
    }
    

    同时尝试使用console.log() 来代替alert。由于字符串长而处于警报状态,因此无法显示整个内容

    【讨论】:

    • 你检查了html部分吗?它是正确的html吗?
    • 是的,它是正确的 html..如果您有其他想法,请给我
    猜你喜欢
    • 2023-03-13
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多