为什么PHP在我的表中插入反引号?

时间:2016-08-06 23:15:15

标签: php ajax html-table

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

enter image description here

创建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>

这怎么可能发生?

1 个答案:

答案 0 :(得分:5)

您的代码中包含以下内容:

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

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