Ajax无法处理无序列表中的列表项(Ajax not working on list items within unordered list)

编程入门 行业动态 更新时间:2024-10-27 05:21:31
Ajax无法处理无序列表中的列表项(Ajax not working on list items within unordered list)

我是编程的初学者。 我尝试在无序列表上使用Ajax来运行列表项(li)id,如下所示:

<script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script> $(document).ready(function() { $("#accordion li").not('.empty').click(function() { var addr = this.id; $.ajax({ url: addr, type: "GET", data: dataString, success:function(data) { alert('I would run those addr here . ' + addr); } }); }); }); </script> <body> <ul id="accordion"> <li id="a1.php"><a href="#">Aaa</a></li> <li class="empty"><a href="#">Bbb</a></li> <li class="empty"><a href="#">Ccc</a></li> <li class="empty"><a href="#">Ddd</a></li> </ul> </body>

上面的代码不起作用,为什么?

I'm beginner in programming. I tried to used Ajax on unordered list to run the list item (li) id like this:

<script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script> $(document).ready(function() { $("#accordion li").not('.empty').click(function() { var addr = this.id; $.ajax({ url: addr, type: "GET", data: dataString, success:function(data) { alert('I would run those addr here . ' + addr); } }); }); }); </script> <body> <ul id="accordion"> <li id="a1.php"><a href="#">Aaa</a></li> <li class="empty"><a href="#">Bbb</a></li> <li class="empty"><a href="#">Ccc</a></li> <li class="empty"><a href="#">Ddd</a></li> </ul> </body>

This code above doesn't work, why ?

最满意答案

$(document).ready(function() { $("#accordion li").not('.empty').click(function() { var addr = $(this).attr('id'); var dataString = "some string"; $.ajax({ url: addr, type: "GET", data: dataString, success:function(data) { alert('I would run those addr here . ' + addr); } }); }); });

$(document).ready(function() { $("#accordion li").not('.empty').click(function() { var addr = $(this).attr('id'); var dataString = "some string"; $.ajax({ url: addr, type: "GET", data: dataString, success:function(data) { alert('I would run those addr here . ' + addr); } }); }); });

更多推荐

本文发布于:2023-08-06 20:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455332.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:列表   列表中   Ajax   working   unordered

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!