dtd14883 2012-01-06 05:05
浏览 22

在jQuery框架中从键盘删除所选项目

i have done frame for drag and drop elements in jQuery. now i want to delete the element from the frame as per requirements.the deletion should from the keyboard. I am trying and can select the item, but cant delete the selected item. my code like that..

        //Select the element
        jQuery(function() {
            jQuery ("#frame").selectable();
        });
        //move to trash_icon
        jQuery
HTML code...
  <div id="frame">
  <span id="title"></span>
  <div id="tbldevs" > </div>
  </div><!-- end of frame -->

i want to know is there any function in jQuery delete can be happened from keyboard.

  • 写回答

1条回答 默认 最新

  • douwei4370 2012-01-06 06:02
    关注

    You need to simply handle keyboard events, like so:

    HTML:

    <div id="frame">
        <span id="title">My Title</span>
        <div id="tbldevs">
            <div id="item1"> This is item 1</div>
            <div id="item2"> This is item 2</div>
        </div>
        <input type="button" id="sel-cancel" value="Cancel Select"/>
    </div>
    

    JS:

    jQuery(function() {
        //make the elements selectable
        $("#tbldevs").selectable();
    
        //handle the events in every element. Only applies to elements which can be handle focus
        $('*').keypress(function(event) {
            if ( event.which == 100 ) { //this is the keycode. 100 is the 'd' key. The delete key is difficult to bind.
                $('.ui-selected').remove();
                //you can add ajax calls here to remove items from the backend
             }
        });
    });
    

    NOTE: The following code only removes the elements from the HTML tree.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题