我有一些从mysql输入的内容,当点击时应该触发alert()... 但是,这不起作用...
这是我从 php/get_answers.php 输入的代码
<?php session_start(); ?>
<?php require_once("../includes/include_all.php"); ?>
<?php $answers = $question->get_answers_for_question($_GET['id']); ?>
<?php while($row = $answers->fetch_array()){ ?>
<!-- ALL ANSWERS HERE -->
<div class = 'answer-row'>
<div class = 'answer-side'>
<div class = 'arrow-contain-answer' type = 'answer' id = 'arrow-up' answer-id = '<?php echo $row["id"]; ?>'></div>
<div class = 'answer-votes-contain'>
<?php echo $row['popularity']; ?>
</div>
<div class = 'arrow-contain-answer' id = 'arrow-down'answer-id = '<?php echo $row["id"]; ?>'></div>
</div>
<div class = 'answer-content'>
<?php
echo $row['content'];
?>
</div>
<div class = 'actions'>
<a href = '#' class= 'add-comment' id = '<?php echo $row["id"]; ?>'> add comment </a>
</div>
</div>
<?php } ?>
这是显示它的页面上的 jquery:
$(".arrow-contain-answer").click(function(){
alert();
});
我想要发生的是,当有人单击“arrow-contain-answer”类的元素时,就会发生一个事件。
我想我之前在通过 mysql/php 将元素“馈送到”页面时遇到过问题。
最佳答案
$(document).on("click", ".arrow-contain-answer", function(){
alert();
});
尝试用这种方式动态添加元素!
关于php - 当元素通过 mysql 显示时,Jquery 事件不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15805724/