Ajax不处理无序列表中的列表项

时间:2016-08-12 08:28:08

标签: php jquery html ajax

我是编程的初学者。我尝试在无序列表上使用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>

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

1 个答案:

答案 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);
            }
        });
    });
});