【问题标题】:How to set the div content dynamically while each load?每次加载时如何动态设置div内容?
【发布时间】:2009-10-03 04:48:48
【问题描述】:

主页.html

我有一个左侧菜单,当点击访问者菜单时,它会在名为“rightcont”的 div 中加载 visitor.html。

$(".rightcont").load("visitor.html");

还有当点击学生菜单时,会在div rightcont上加载students.html

$(".rightcont").load("students.html");

但默认情况下,我在第一次访问页面时在 rightcont 中加载了welcome.html。

我的问题是,当用户单击网站其他部分中名为 STUDENTS 的链接时,它会重定向到 home.html,其中“rightcont”div 显示welcome.html。我需要 rightcont 来显示students.html。

如何根据点击的链接动态改变它

【问题讨论】:

  • 我正要回答这个问题并大喊“用 jQuery!”但我可以看到你已经这样做了,对我来说太糟糕了。
  • 你是什么意思??? @卡森迈尔斯
  • 我建议您尝试更清楚地解释自己,更重要的是,我不建议对试图帮助您的人投反对票。祝你好运。

标签: php jquery css


【解决方案1】:

用途:

return false;

确保在单击链接时不会重定向页面。点击链接时可以加载div rightcont。

$("#students").click(function() {
    $(".rightcont").load("students.html");
    return false;
});

(您需要在锚标记中包含 id="students" 才能使该选择器起作用)

【讨论】:

  • 但是学生链接和rightcont在不同的页面,就是那个页面............
  • 你需要从源页面传递一些变量,要么在帖子中,要么注入到目标页面中。
【解决方案2】:

在学生页面的超链接上链接到students.php?page=students,并将这部分php添加到页面中

if($_get['page'] == "students")
{
?>
 <script type="text/javascript">
 $(".rightcont").load("students.html"); 
 <script>
 <?
}
else
{
 <script type="text/javascript">
 $(".rightcont").load("visitor.html"); 
 <script>
}

【讨论】:

  • 这应该可以工作,但可以通过将 $_get['page'] 设为变量,然后根据该变量加载 rightcont 来使其更加健壮,因此它也适用于访问者或任何其他链接.
猜你喜欢
  • 2014-02-23
  • 2013-09-30
  • 1970-01-01
  • 2011-11-08
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多