我有两个页面:edit.php
和list-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
收听点击?
答案 0 :(得分:0)
将事件绑定到文档上,并将其过滤到.trg-delete
。
$(function){
$(document).on('click', '.trg-delete', function() {
...
});
});