[英]jQuery losing click handler after loading div
This is situation: Im making content changing of my page with .load('page.php') function. 这是一种情况:我使用.load('page.php')函数更改页面内容。 But my problem is following. 但是我的问题在后面。 When i change content like this , my .click() functions dont work anymore. 当我这样更改内容时, .click()函数不再起作用。
Here is my .js code: 这是我的.js代码:
$(document).ready(function(){
$(".menu_inner").bind('click',function(){
var product = $(this).attr('prod');
produkt="modules/"+product+".php";
})
$(".menu_list_home").click(function(){
$("#contentwrapper").load('modules/homepage.php');
})
})
It is ok with homepage bind cause div where it is refreshed is not where homebutton is. 可以使用主页绑定原因div刷新而不是homebutton所在的位置。 It is working when page loads. 页面加载时它正在工作。 As soon as i click on home, there is nothing to do. 我一点击首页,就无事可做。 It looks like it was unbinded. 看起来像是未绑定的。 Any guess? 有猜到吗?
Martin. 马丁
I belive that dom having class menu_inner
is also getting changed when you load 'contentwrapper'. 我相信当您加载“ menu_inner
,具有类menu_inner
dom也将被更改。 Use this: 用这个:
$(document).on('click', '.menu_inner', function(){
ar product = $(this).attr('prod');
produkt="modules/"+product+".php";
} );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.