jQuery的点击无行为 [英] Jquery no behavior on click
问题描述
我有一个ID为#wrapper
的div.在它旁边,我有一个按钮.单击该按钮时,将触发ajax调用,并返回具有名为.calendarDate
的类的div列表.一切正常,#wrapper
填充良好.
I have a div with an id called #wrapper
. Next to it I have button. When the button is clicked, an ajax call is triggered returning a list of divs with a class called .calendarDate
. Everything works great, #wrapper
is populated fine.
现在,我尝试在该.calendarDate
类上创建一个click事件,但是它不起作用.奇怪的是,我应用于该类的CSS属性运行正常.希望有人能承认这种奇怪的行为.通过他的方式,我的调试器中没有错误.预先感谢您的答复.干杯.马克
Now I am trying to have a click event on that .calendarDate
class, but it is not working. The strange part is that the CSS properties I apply to that class are working properly. Hope someone can acknowledge about that strange behavior. By he way, no errors in my debugger. Thank you in advance for your replies. Cheers. Marc
我的PHP:效果很好
Here i set my variables...
while($input<$inDays){
++$input;
$test=$input." days";
if($input<0){$attribut='"avant"';}else{$attribut='"apres"';}
echo '<div class="calendarDate" indiDate=' .$attribut. '>' .date('Y-m-d', strtotime($test)). '</div>';
}
我的JS:
$(document).ready(function() {
$('#wrapper').load('php/calendar2.php');
$('.calendarDate').click(function(){
alert('Whaou!');
});
});
我的HTML:
<div id="wrapper"></div>
<input id="envoyer" type="submit" multiplicateur="1">
推荐答案
听起来好像您在将click事件绑定到calendarDate类之前一样.尝试使用此方法绑定事件处理程序...
It sounds like you're binding the click event to the calendarDate class before it exists. Try using this to bind the event handler instead...
$(document).on("click", ".calendarDate", function() {
// etc
}
这会将click事件处理程序触发到具有calendarDate类的所有元素,而不管它们是否存在于准备就绪的文档中.
That will fire the click event handler to all elements with a class of calendarDate, regardless of whether they exist at document ready or not.
这篇关于jQuery的点击无行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!