开发者

Remove DOM object on click and buttonpress

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜