简体   繁体   English

如何在div中打开链接?

[英]How to make link open inside a div?

I am trying to get 3 links to open in a certain div. 我试图在某个div中打开3个链接。 I understand ajax can help me do this, but for whatever reason I cannot get it to work right. 我知道ajax可以帮助我做到这一点,但是出于任何原因我都无法使其正常工作。 (I'm new to ajax, and javascript in general) If anyone can help me out, I would appreciate it! (我是ajax和javascript的新手)如果有人可以帮助我,我将不胜感激! And I have looked around for my problem, and I can't seem to find any useful information. 而且我到处都在寻找我的问题,而且似乎找不到任何有用的信息。 At least not to the extent I need it. 至少没有达到我需要的程度。

<div id="tickcontain">
    <div id="ticker"><ul class="bxslider">
        <li><img src="../images/01.png" /></li>
        <li><img src="../images/02.png" /></li>
        <li><img src="../images/03.png" /></li>
        <li><img src="../images/04.jpg" /></li>
    </ul></div>
<div id="calender"><center><?php include ("sources/status.php");?></center></div>

<div id="hallofame"> //**Want the information to load here**// </div>

<div id="events">
    <div id="tab1">Register</div> //**Want these 3 to be my links**//
    <div id="tab2">Events</div>   //**Want these 3 to be my links**//
    <div id="tab3">Updates</div>  //**Want these 3 to be my links**//
</div>
<div id="adspace"></div>

I have this inserted into my header (top of page): 我将此插入到标题(页面顶部)中:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

and I have this on the page where I want the links/div to happen. 我在希望链接/ div出现的页面上有此标签。 (only tried testing out the first link.) (仅尝试测试第一个链接。)

<script type=text/javascript"> 
    $("#tab1").click(function(){
        $("#hallofame").load('pages/register.php');
    });
</script>

There are no links in your source code. 您的源代码中没有链接。 Let's add them and change their default behavior: 让我们添加它们并更改其默认行为:

<a data-target="#halloffame" href="pages/register.php">Register</a>
<a data-target="#halloffame" href="pages/events.php">Events</a>
<a data-target="#halloffame" href="pages/updates.php">Updates</a>

<div id="halloffame"></div>

<script>
  $('[data-target]').click( function (e) {
    var target = $($(this).attr('data-target'));
    target.load($(this).attr('href'));

    e.preventDefault(); // prevent anchor from changing window.location
  });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM