English 中文(简体)
j
原标题:Traversing Table with jQuery

我有一个关于“数据顺序”的“超文本属性”的表格,该表只是一个显示表(表格)顺序的分类账。 如今,该法典只检查被点击的T TR前面的行踪——我试图做的是,让它把所有行走在桌前,一旦发现数量超过(不是大于或等于)之后,它就称为输电功能。

这里是用来推移row的 j。

function adjustRank(id, e) {
    var url = "/ajax/moveup/" +  aid;
    var row = $(e).closest("tr").get(0);
    var prevRow = $(row).prev().get(0);
    var moveUp = false;
    var prevRowOrder = parseInt($(prevRow).attr("data-order"));
    var rowOrder = parseInt($(row).attr("data-order"));

    $.ajax({
        type: "POST",  
        url: url,
        data: {aid: aid},
        dataType: "json",
        success: function () 
        { 
            if(rowOrder + 1 > prevRowOrder)  // think this is where I need to traverse the table
                swapRows(row, prevRow);
        },
        failure: function () { alert("Error processing request."); }
    });
}

and here are a couple of items in the table for example:

<table id="listings" style="min-height:150px; width:100%;">
    <tr id="1" data-order="11"><td>1</td><td align="left"><span onclick="adjustRank( ace93485-cea5-4243-8294-9f3d009aba3d , this)" style="cursor:pointer;">Lindsey Vonn</span></td><td></td></tr>
    <tr id="2" data-order="6"><td>2</td><td align="left"><span onclick="adjustRank( 9f83aed6-b99a-4674-a8b7-9f3d009aba38 , this)" style="cursor:pointer;">Al Horford</span></td><td></td></tr>
    <tr id="3" data-order="5"><td>3</td><td align="left"><span onclick="adjustRank( d48a52bd-17e9-4631-9a2e-9f3d009aba39 , this)" style="cursor:pointer;">Derek Jeter</span></td><td></td></tr>
</table>
最佳回答

您可以再次介入,解决这一问题。 请参看该守则。

window.adjustRank = function(id, el) {
    var orderDiff = 1; 
    var row = $(el).closest("tr");
    var order = parseInt(row.attr("data-order")) + orderDiff;
    row.attr("data-order", order);

    var prevRow = row.prev();
    if(prevRow.get(0)){
        moveUp(order, row, prevRow);
    }
}

window.moveUp = function(order, row, prevRow){
    if(order > parseInt(prevRow.attr("data-order"))){
        var prevPrevRow = prevRow.prev();
        if(prevPrevRow.get(0)){
            moveUp(order, row, prevPrevRow);
        } else {
            prevRow.before(row);
        }
    } else {
        prevRow.after(row);
    }
}

如果你通过日本宇宙航空研究开发机构获得orderDiff,那么该守则就会成为你们的美国宇宙航空研究开发机构所称的成功功能。 请参看

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签