Pretty sure i'm going the complete wrong direction with this. I want to click an object, then delete it by pressing the 'd' key.
<script>
$('#In_Play .card').click().keypress(function(event) {
if (event.keyCode == '100') {
$(this).re开发者_StackOverflowmove();
}
});
</script>
I think something like this would work:
$('#In_Play .card').click(function(){
$(this).data('delcandidate', true).focus();
}).keypress(function(event){
if($(this).data('delcandidate') == true && event.keyCode == '100'){
$(this).remove();
}
}).blur(function(){
$(this).data('delcandidate', false);
});
the thing is keypress will only be fired on elements that can have focus (inputs, a). I think you can extend this to other elements by adding a tabindex but im not sure how cross browser any of this is going to be.
精彩评论