在加载AJAX页面后调用Javascript函数 [英] Calling Javascript function after loading an AJAX page
问题描述
我不是程序员,所以如果我的问题没有多大意义,请道歉。
I'm not a programmer so I apologize if my question doesn't make a lot of sense.
但基本上我有一个index.php一组过滤器(按项目,年份,月份),并且在按下submit后,将变量发送到filterData.php以在一些SQL语句中使用。
But basically I have one page index.php that has a set of filters (by project, year, month) and after pressing submit sends the variables to filterData.php to be used in some SQL statements.
图像缩略图表的形式返回到index.php中的div。我想做的是,当用户点击图像时,边框颜色将改变以突出显示当前对象。
The results in the form of a table of image thumbnails are returned to a div in index.php. What I want to do is have it so when the user clicks on an image the border color will change to highlight the current object.
<script type="text/javascript">
$(document).ready(function () {
$('.thumbnail_small').click(function(){
$(this)
.css('border-color','#000')
.siblings()
.css('border-color','#ccc');
});
});
</script>
^这是我现在的脚本,如果缩略图表被硬编码到索引.php。一旦我通过filterData.php加载表,它不再工作。
^ That is the script I have right now and it works if the table of thumbnails is hardcoded into index.php. Once I have the table loaded through filterData.php, it doesn't work anymore.
这是什么原因,我如何解决它?
What is the reason for this and how can I work around it?
推荐答案
一旦我通过filterData.php加载表,它不工作
Once I have the table loaded through filterData.php, it doesn't work anymore.
使用 live
或更高版本 开
取决于您使用的jQuery版本:
Use live
or better on
depending on version of jQuery you are using:
$('#mainContainer').on('click', '.thumbnail_small', function(){
$(this)
.css('border-color','#000')
.siblings()
.css('border-color','#ccc');
});
或
$('.thumbnail_small').live('click', function(){
$(this)
.css('border-color','#000')
.siblings()
.css('border-color','#ccc');
});
对于以后或动态添加的元素,必须使用 / code>或
上
。
For elements that are added later or dynamically, you got to use live
or on
.
这篇关于在加载AJAX页面后调用Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!