我是编程的初学者。我尝试在无序列表上使用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>
上面的代码不起作用,为什么?
答案 0 :(得分:0)
$(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);
}
});
});
});