jquery如何获得最远的元素

时间:2015-01-29 11:33:16

标签: javascript jquery html

我有网格,其中绿色方块是我的.smFly,蓝色方块是元素可用元素,我可以移动我的.smFly类,我想添加.css("border:1px solid blue;") to them;

网格看起来像:http://scr.hu/14ow/ei43o

我的代码如下:

var myElem = "smFly";
var myAvPos = function(myElem){

var elemsGrid = [[1,0][1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[1,9],[2,0][2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[3,0][3,1],[3,2],[3,3],[3,4],[3,5],[3,6],[3,7],[3,8],[3,9],[4,0][4,1],[4,2],[4,3],[4,4],[4,5],[4,6],[4,7],[4,8],[4,9],[5,0][5,1],[5,2],[5,3],[5,4],[5,5],[5,6],[5,7],[5,8],[5,9],[6,0][6,1],[6,2],[6,3],[6,4],[6,5],[6,6],[6,7],[6,8],[6,9]];

//上面是二维数组[x,y]

中的网格字段
    if ($('.'+myElem+'> input').is(':checked')) {
        var fieldY = $('tbody').find('.'+myElem).parent().prop('className');
        var fieldX = $('.'+fieldY).parent().prop('className');
        fieldX = fieldX.substring(1);
        console.log(fieldX);

        var avPos = fieldX + 2; And here I dont know how to calculate new pos that is markered by blue color in screen.

    } else {
        alert("Check element first!");
    }

}

HTML看起来像:

<tbody>
                <tr class="x1">
                    <td class="y0">
                        <label class="smFly">
                            <input type="checkbox">
                        </label>
                    </td>
                    <td class="y1">
                        <label>
                            <input type="checkbox">
                        </label>
                    </td>
                    <td class="y2">
                        <label>
                            <input type="checkbox">
                        </label>
                    </td>
                    <td class="y3">
                        <label>
                            <input type="checkbox">
                        </label>
                    </td>
                </tr>
                <tr class="x2">
                    <td class="y0">
                        <label class="selected">
                            <input type="checkbox">
                        </label>
                    </td>
                    <td class="y1">
                        <label>
                            <input type="checkbox">
                        </label>
                    </td>
                    <td class="y2">
                        <label>
                            <input type="checkbox">
                        </label>
                    </td>
                    <td class="y3">
                        <label>
                            <input type="checkbox">
                        </label>
                    </td>

有任何帮助吗?请。

0 个答案:

没有答案