2011-01-26 79 views

回答

0

一个id不能以数字开头,这样可能会导致问题。

除此之外,它取决于您的JavaScript位于何处以及如何以及何时将其附加到您的事件处理程序。

如果JavaScript包含在DIV 1中加载的代码中,应该没有问题,但是如果它已经存在于页面中,则需要尽快将其附加到新加载的DIV 1中它被加载。

请参阅jQuery .live() function documentation的详细解释我的意思。

+0

对不起,我做错了,它调用Div2,但是,我不想使用Jquery这一个。似乎Div1内部无法访问div2,而div2内部我无法访问div1 – Loruaasd 2011-01-26 15:43:28

0

因此,在DIV1的内容中,您有一些链接,比如想要将内容加载到DIV2中?然后你需要做的事情是将事件监听器添加到DIV1中的链接中,以便当它们被点击时,他们将创建AJAX调用,将内容加载到DIV2中。

我建议使用jQuery(http://jquery.com/),你可以做这样的事情:

// getting the content into DIV1 
$('#div1').load('/path/to/backend.php', function() 
{ 
    // the ajax request is complete, so let's add listeners to the a tags in DIV1 
    $('#div1 a').click(function() 
    { 
     // this clears DIV2's content 
     $('#div2').empty(); 

     // and now we load some ajax by getting the href of the a tag and passing that to our backend 
     $('#div2').load('/path/to/backend.php', { page: $(this).attr('href') }; 
    }); 
}); 

你可以在这里阅读更多:http://api.jquery.com/load/