jQuery AJAX加载多个href链接

时间:2022-08-26 20:19:17

Hey guys I'm trying to get the following to work...

嘿伙计们,我正努力让以下工作......

  • demo_test.txt to load into the "div1" container
  • demo_test.txt加载到“div1”容器中
  • only have a href id "test" to trigger it
  • 只有一个href id“test”来触发它

<!DOCTYPE html>
<html>

<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  <script>
    $(document).ready(function() {
      $("test").click(function() {
        $("#div1").load("demo_test.txt");
      });
    });
  </script>
</head>

<body>

  <div id="div1">
    <h2>Let jQuery AJAX Change This Text</h2>
  </div>

  <a id="test" href="#">Get External Content</a>

  <br>

  <a id="google" href="http://www.google.com/">Google</a>

</body>

</html>

Currently it doesn't run, but if I remove the Google line, it works. Is there something else I'm missing? Thanks!

目前它没有运行,但如果我删除了Google系列,它就可以运行。还有什么我想念的吗?谢谢!

1 个解决方案

#1


4  

Change your jQuery click handler to this:

将您的jQuery单击处理程序更改为:

$("#test").click(function() {

I've added a # in front of test to properly select your anchor tag.

我在测试前添加了一个#来正确选择你的锚标签。

#1


4  

Change your jQuery click handler to this:

将您的jQuery单击处理程序更改为:

$("#test").click(function() {

I've added a # in front of test to properly select your anchor tag.

我在测试前添加了一个#来正确选择你的锚标签。