0

我正在尝试将 JQuery load() 中的数据附加到表中。虽然我能够成功地将数据附加到表中,但附加结果的格式未与表的其余部分一致。

表格的当前格式(附加后)

+---------------------------------------------------+
|                    Data                           |
-----------------------------------------------------
|    Data                |            Data          |
-----------------------------------------------------
|    Data                |            Data          |
-----------------------------------------------------
|Append data|Append data |
--------------------------
|Append data|Append data |
--------------------------
|Append data|Append data |
--------------------------
|Append data|Append data |
--------------------------

所需格式

+---------------------------------------------------+
|                    Data                           |
-----------------------------------------------------
|    Data                |            Data          |
-----------------------------------------------------
|    Data                |            Data          |
-----------------------------------------------------
|      Append Data       |        Append Data       |
 -----------------------------------------------------
|      Append Data       |        Append Data       |
-----------------------------------------------------
|      Append Data       |        Append Data       |
-----------------------------------------------------

代码摘录:

    <table id="edititemtable" border='1'>

<tr>
    <td colspan='2'>Item Info</td>
</tr>

<tr>
    <td>Select Category: </td>
    <td>
        <select id='changeitemcat' name='changeitemcat'></select>
    </td>
</tr>

<tr>
    <td>Select SubCategory: </td>
    <td>
        <select id='changeitemsubcat' name='changeitemsubcat'></select>
    </td>
</tr>

<div id="details" name="details">
</div>

</table>

使用的 JQuery 的提取

$("#edititemtable").append($("#details").load('changeitem.php?cat='+cat+'&subcat='+subcat+'&item='+item));

.load() 文件的提取

while($extractdetails=$getitem->fetch(PDO::FETCH_ASSOC))
{
//Data is saved into the associated variables


echo"<tr>";
    echo"<td>";
        echo"Item Name";
    echo"</td>";
    echo"<td>";
        echo"<input type='text' id='changeitemname' name='changeitemname' value=$itemname size='30' maxlength='50' />";
    echo"</td>";
echo"</tr>";    

echo"<tr>";
    echo"<td>";
        echo"Item Price";
    echo"</td>";
    echo"<td>";
        echo"<input type='text' id='changeitemprice' name='changeitemprice' value=$itemprice size='7' maxlength='7' />";
    echo"</td>";
echo"</tr>";

echo"<tr>";
    echo"<td>";
        echo"Item Info";
    echo"</td>";
    echo"<td>";
        echo"<textarea class='textarea' id='changeiteminfo' name='changeiteminfo' col='10' rows='10' maxlength='300' >$iteminfo</textarea>";
    echo"</td>";
echo"</tr>";


echo"<tr>";
    echo"<td>";
        echo'<form id="changeitem" name="changeitem" method="POST" action="">';
            echo"<input type='hidden' id='changeitemid' name='changeitemid' value='$itemid' />";
            echo"<input type='submit' id='changeitemsubmit' name='changeitemsubmit' value='Save Changes' />";
        echo"</form>";
    echo"</td>";
echo"</tr>";

}

问题

我如何获得所需的格式?

为什么附加数据被强制进入其中之一?

解决方案:

<table id="edititemtable" border='1'>

<tr>
    <td colspan='2'>Item Info</td>
</tr>

<tr>
    <td>Select Category: </td>
    <td>
        <select id='changeitemcat' name='changeitemcat'></select>
    </td>
</tr>

<tr>
    <td>Select SubCategory: </td>
    <td>
        <select id='changeitemsubcat' name='changeitemsubcat'></select>
    </td>
</tr>

<tr>
    <td colspan="2" id="details" name="details">
    </td>
</tr>

</table>

Ps 我目前正在使用 HTML 5 和 PHP

4

2 回答 2

1

将 a<div>放入 a<table>是无效的(如果它不在 a <tr>and内<td>),因此如果您尝试这样做,您将看到“不正确”(就您而言)结果。最简单的解决方案是将其从 a 更改<div>为元素,这对于位于元素内部并包含表格行<tbody>是完全有效的:<table>

<table id="edititemtable" border="1">
    <tr>
        <td colspan="2">Item Info</td>
    </tr>
    <tr>
        <td>Select Category:</td>
        <td>
            <select id="changeitemcat" name="changeitemcat"></select>
        </td>
    </tr>
    <tr>
        <td>Select SubCategory:</td>
        <td>
            <select id="changeitemsubcat" name="changeitemsubcat"></select>
        </td>
    </tr>
    <tbody id="details"></tbody>
</table>

也无需调用.append(),因为该元素已经在表的末尾。做就是了:

$('#details').load('changeitem.php?cat='+cat+'&subcat='+subcat+'&item='+item);
于 2013-09-02T14:31:42.847 回答
0

在 HTML 中

<table id="edititemtable" border='1'>

<tr>
    <td colspan='2'>Item Info</td>
</tr>

<tr>
    <td>Select Category: </td>
    <td>
        <select id='changeitemcat' name='changeitemcat'></select>
    </td>
</tr>

<tr>
    <td>Select SubCategory: </td>
    <td>
        <select id='changeitemsubcat' name='changeitemsubcat'></select>
    </td>
</tr>
    <tr>
        <td colspan="2">
<table id="details" name="details" >
</table>
        </td> 
        </tr>
</table>

在js中

  $("#edititemtable").append($("#details").load('changeitem.php?cat='+cat+'&subcat='+subcat+'&item='+item));
于 2013-09-02T13:10:50.303 回答