dongmuyuan3046 2015-07-27 09:15
浏览 24
已采纳

从加载的内容触发(“点击”)[重复]

This question already has an answer here:

I have two pages: edit.php and list-questions.php. I am wanting to load content from list-questions to edit, this works.

I also want to be able to trigger on('click') from list-questions within edit.

Within Edit.php I have:

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

And within list-questions.php I have:

<?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
};

When questions are found it outputs something similar to (simplified):

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

How would I go about listening for a click from .trg-delete in edit.php ?

</div>
  • 写回答

1条回答 默认 最新

  • dongxing2015 2015-07-27 09:18
    关注

    Bind the event on the document, and filter it to .trg-delete.

    $(function){
        $(document).on('click', '.trg-delete', function() {
            ...
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?