如何打开页面的特定部分使用jquery

时间:2012-02-19 13:42:50

标签: jquery

我的链接有问题应该打开另一个页面的特定部分使用jquery。

index.php文件的简化视图:

<?php
if (!isset($a)) $a = '';
switch($a)
{
case 1:
default:
print('<div class"left">the left menu that contains links to specific parts of the     page</div><div class="main">content of the page</div>');
break;
case 2:
echo "second part";
break;
case 3:
echo "third part";
break;
}
?>

在这个页面上,我正在使用jquery在“main”DIV中打开该文件的某些部分。 当我点击左边的链接时,使用jquery,我可以打开“main”DIV中“第三部分”的内容; 此页面如下:

 --------------------   ----------------------------------
|                    | |                                  |
| the left menu that | |                                  |
| contains links to  | |         third part               |
| specific parts of  | |                                  |
| the     page       | |                                  |
 --------------------   ----------------------------------

我需要的是jquery代码,允许点击位于其他页面的链接,该链接将打开index.php文件,其中包含部分内容,如上例所示。

现在,我所能做的就是打开index.php中“trird part”所在的部分

 ----------------------------------
|                                  |
|                                  |
|         third part               |
|                                  |
|                                  |
 ----------------------------------

但我无法使用其他页面的链接在同一页面打开左边的meny和主div。我怎么能这样做?

我在第二页上使用的Jquery代码是:

$('.prt').click(function () {
var adr=$(this).attr('rel');
window.open(adr);
})

链接的HTML:

<div class="prt" rel="index.php?a=3">link</div>

感谢所有建议&amp;指针

1 个答案:

答案 0 :(得分:0)

如果您只想显示菜单,请将其从switch-case语句中删除并放在顶部。

我认为您不想使用window.open并在网站右侧的cotainer中打开目标网页。

我建议动态地这样做:

$('#main').load('content_3.html'); // Sample!
相关问题