我正在尝试动态加载 PHP 文档,该文档在同一脚本上使用一些 jQuery 事件,因此加载网页后 jQuery 效果不起作用。
例如:
$(document).ready(
function(){
main();
function main()
{
$('#game1').hover(
function(){ $('#info1 p').slideDown('fast'); },
function(){ $('#info1 p').slideUp('fast'); }
);
$("#izquierda a").click(function()
{
$('#izquierda ul').hide();
$('#content').slideDown();
$('#menu').slideDown();
$('#contentMin').hide();
$("#gameContent").load("content.php", main()); // i try loading main() again so the effects would have some effect? doesn't work though
});
}
});
在 content.php 中,我从数据库加载数据并将其放置在名为 #game1
的 div 中,该 div 使用悬停效果,但在加载 content.php 后它不起作用。如果没有从 content.php 加载它,相同的脚本也可以工作。
那么我怎样才能让它发挥作用呢?
抱歉,我是新手,谢谢!
最佳答案
由于服务器需要渲染代码,所以这里需要使用AJAX。查找 jQuery ajax 函数:http://api.jquery.com/jQuery.ajax/ .
$("#gameContent").ajax({
url: "content.php",
success: function(){ main(); }
});
关于php - 使用jquery动态加载php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8282546/