简体   繁体   English

带有多个href链接的jQuery AJAX加载

[英]jQuery AJAX loading with multiple a href links

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“测试”来触发它

 <!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. 目前它没有运行,但是如果我删除了Google产品线,它就可以工作。 Is there something else I'm missing? 还有其他我想念的东西吗? Thanks! 谢谢!

Change your jQuery click handler to this: 将您的jQuery click处理程序更改为:

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

I've added a # in front of test to properly select your anchor tag. 我在test前添加了# ,以正确选择您的锚标记。

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

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