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); } }); }); });更多推荐
发布评论