【问题标题】:Why is PHP inserting backticks into my table?为什么 PHP 在我的表中插入反引号?
【发布时间】:2016-08-07 07:28:46
【问题描述】:

我对这种行为感到困惑。这是输出:

PHP 表创建:

$table = '<div class="table-responsive"><table class="table table-stripped">
        <thead>
        <tr>
            <th>Name</th>
            <th>Title</th>
            <th>Work Type</th>
            <th>Genre</th>
            <th>PDF</th>
            <th class="fa fa-envelope-o" style="font-size: larger; color: blue;" title="Send Writer Email"></th>
            <th class="fa fa-thumbs-o-up" style="font-size: larger; color: green;"  title="Request Manuscript"></th>
            <th>Rating</th>
        </tr></thead><tbody>';
foreach ($rows as $row) {
    $table .= "<tr class='trow'>
        <td class='fullname'>" . $row['Name'] . "</td>
        <td class='title'>" . $row['Title'] . "</td>
        <td class='form-type'>" . $row['FormType'] . "</td>
        <td class='genre'>" . $row['Genre'] . "</td>
        <td><a class='synopsis' href='uploads/" . $row['Filename'] . "' target='_blank'>synposis</a></td>
        <td><input type='checkbox' class='sendemail' /></td>`
        <td><input type='checkbox' class='email-request-manuscript' /></td>
        <td><div class='rating'></div></td>
        <td class='hidden email'>" . $row['Email'] . "</td>
        <td class='hidden id'>" . $row['ID'] . "</td>
        <td><input class='hidden writer-rating' value='" . $row['Rating'] . "'/></td>
        </tr>";
};
$table .= "</tbody></table></div>";
echo $table;

JS(从 PHP 中检索表)

$('#table-list').empty().append(table);
console.log($('#table-list').html());

console.log(一个表格行)

<div class="table-responsive">`
                `
                `
                `
                `
                `
                `
                `
                <table class="table table-stripped">
                <thead>
                <tr>
                    <th>Name</th>
                    <th>Title</th>
                    <th>Work Type</th>
                    <th>Genre</th>
                    <th>PDF</th>
                    <th class="fa fa-envelope-o" style="font-size: larger; color: blue;" title="Send Writer Email"></th>
                    <th class="fa fa-thumbs-o-up" style="font-size: larger; color: green;" title="Request Manuscript"></th>
                    <th>Rating</th>
                </tr></thead><tbody><tr class="trow">
                <td class="fullname">Ron Tornambe</td>
                <td class="title">The Hunting of the Snark</td>
                <td class="form-type">Short Story</td>
                <td class="genre">Absurdist/surreal/whimsical</td>
                <td><a class="synopsis" href="uploads/3752805599.pdf" target="_blank">synposis</a></td>
                <td><input type="checkbox" class="sendemail"></td><td><input type="checkbox" class="email-request-manuscript"></td>
                <td><div class="rating"></div></td>
                <td class="hidden email">ron.tornambe@bunkerhill.com</td>
                <td class="hidden id">101</td>
                <td><input class="hidden writer-rating" value="3"></td>

怎么会这样?

【问题讨论】:

  • 尚无线索,但滴答计数与行计数相同吗?
  • 实际上是这样,但@ritzer 做到了。我在复选框后有一个反引号。为什么我再也看不到他的评论了?
  • 一个程序完全按照你说的去做的经典案例;)
  • 我也没有看到它......不过,很奇怪,它们被插入到不同的位置。也许jquery参与其中? (附加)
  • @rontornambe 我删除了它,因为反引号出现在不同的地方,这让我相信这不是原因。

标签: php ajax html-table


【解决方案1】:

你的代码中有这个:

<td><input type='checkbox' class='sendemail' /></td>`

最后是反引号,它传播到输出。删除它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多