ajax调用无法处理标记点击

时间:2014-03-19 01:08:01

标签: javascript jquery ajax

为什么当我点击$.load标签时,ajax呼叫<td>无法正常工作? 顺便说一下这是脚本

$("body").on("click", ".license-table td", function(){
        console.log('ehhh')
        var pane = $(this).parent('.license-table').data("pane");
        var url = $(this).parent('tr').data("href");
        $(pane).load(url, function(){
            $(".table-content").css({
                height: '500px'
            }).jScrollPane({
                autoReinitialise: true,
                hideFocus: true
            });
        });
    });

这是标记。

<div class="tab-pane" id="license">
                        <div class="row content-tools">
                            <div class="col-md-3">
                                <div class="options enabled">
                                    <a href="distribute-license-modal.php" data-toggle="modal" data-target="#modal" data-dismiss="modal">Allocate Licenses</a>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="options enabled">
                                    <a href="unallocate-license-modal.html" data-toggle="modal" data-target="#modal" data-dismiss="modal">Unallocate Licenses</a>
                                </div>
                            </div>
                            <div class="col-md-3">&nbsp;</div>
                            <div class="col-md-3">
                                <form action="">
                                    <input type="text" name="q" class="col-md-12 search"/>
                                </form>
                            </div>
                        </div>
                        <div class="row" style="margin:0">
                            <div class="table-content col-md-12">
                                <div class="inner table-responsive pade-content-big">
                                    <table class="table dtable license-table" data-pane="#license">
                                        <tr>
                                            <td width="30%">&nbsp;</td>
                                            <td width="10%">Total</td>
                                            <td width="10%">Distributed</td>
                                        </tr>
                                        <tr data-href="license-details.html">
                                            <td><a href="license-details.html" class="ajax-link black-link" data-pane="#license">Product Name</a></td>
                                            <td>200</td>
                                            <td>50</td>
                                        </tr>
                                        <tr data-href="license-details.html">
                                            <td><a href="license-details.html" class="ajax-link black-link" data-pane="#license">Product Name</a></td>
                                            <td>200</td>
                                            <td>120</td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

console.log("ehhh")显示在我的控制台窗口中,但XHR请求没有显示出来。怎么了? :(

1 个答案:

答案 0 :(得分:1)

.parent()函数获取直接父元素。当您提供选择器参数时,它会过滤结果;在找到匹配的祖先之前,它不会上升到祖先链。为此,您应该使用.closest()函数:

var pane = $(this).closest('.license-table').data("pane");