开发者

Deselecting rows in table using jquery

In this code, if I press shift+down key it selects multiple rows and if I press the up key, it is deselecting. But if I press shift+uparrow only deselection should happen.

Normally using the up and down keys, I can navigate up and down.

eg:If table has 10 rows and using shift+downarrow, I select 3 rows, and after this I press the down arrow to row 6. From this I should be able to select rows again with deselection the previous selected rows.

In my code you can see

if(code == 13) { //Enter keycode
    alert(did);
    if(did != undefined){
        wi开发者_JAVA百科ndow.open('keyboard.php?q=' + did);
    }
}

Here, if I press the enter key, it should take me to another page but for some reason I am getting an undefined error. What am I doing wrong?


the issue appears to be how the script is setting did

$(document).keyup(function(e) {
    var current = rows.filter(".ui-selected"),
        selected = $(); //an empty jQuery object
    ...
            case 13:
                var code = (e.keyCode ? e.keyCode : e.which);
                var did = current.data('docID');
    ...
}

since you're watching for keyUp events on the document the document is what is passed in as this in the event call

var did = $(this).data('docID');

you should be able to replace $(this) with current to get the desired effect

var did = current.data('docID');


Have you tried using typeof(did) != 'undefined'

Your error is here:

if (event.shiftKey) {
        selected = selected.add(current);
    }

should be e not event. Works for me except that the page is not found when pressing enter, but the event works.

http://jsfiddle.net/hKZqS/61/ -> working fiddle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜