从加载的内容触发(“点击”)

时间:2015-07-27 09:15:54

标签: javascript php jquery

我有两个页面:edit.phplist-questions.php。我希望将内容从list-questions加载到edit,这可行。

我还希望能够在on('click')list-questions触发edit

Edit.php内我有:

<script>
$(document).ready(function() {
    var questions = $('div.questions');
    $('div.questions').load('list-questions.php?id=<?php echo $catID; ?>');

    setInterval(function() {
        $('div.questions').load('list-questions.php?id=<?php echo $catID; ?>');
    }, 5000);


    $('.trg-delete').on('click', function() {
        console.log(true);
    });
});
</script>
<div class="questions">
</div>

list-questions.php内我有:

<?php
$catID = $_GET['id'];

$getItems = $con->prepare("SELECT itemID,itemName,itemType FROM items WHERE catID=?");
$getItems->bind_param("i", $catID);
$getItems->execute();
$getItems->store_result();
if($getItems->num_rows > 0) {
?>
<table class="full outline">
  <tr class="head">
    <td colspan="2"><p>Questions</p></td>
  </tr>
<?php
  $getItems->bind_result($itemID,$itemName,$itemType);
  while($getItems->fetch()) {
?>
  <tr>
    <td><p><?php echo $itemName; ?></p></td>
    <td class="fixed-100 options">
      <a class="trg-delete confirm" data-id="<?php echo $itemID; ?>"><i class="fa fa-fw fa-close"></i></a>
    </td>
  </tr>
<?php }; ?>
</table>
<?php } else { ?>
<table class="full outline">
  <tr class="head">
    <td colspan="2"><p>Questions</p></td>
  </tr>
  <tr>
    <td colspan="2"><p class="alert">No Questions Found</p></td>
  </tr>
</table>
<?php
};

当发现问题时,它会输出类似于(简化)的内容:

<div class="questions">
    <table>
        <tr>
            <td><p>Questions</p></td>
        </tr>
        <tr>
            <td><p>Question?</p></td>
            <td>
                <a class="trg-delete" data-id="1"><i></i></a>
            </td>
        </tr>
    </table>
</div>

如何从.trg-delete中的edit.php收听点击?

1 个答案:

答案 0 :(得分:0)

将事件绑定到文档上,并将其过滤到.trg-delete

$(function){
    $(document).on('click', '.trg-delete', function() {
        ...
    });
});