在Ctrl Click上禁用单击操作

时间:2011-01-19 17:29:52

标签: jquery jstree

我面临着一种奇怪的情况。单击我绑定一个将调用AJAX函数的事件,但是当我按下Ctrl时,应该禁用默认的单击操作。有什么方法可以实现它..请分享有关如何进一步的任何想法..

$('#demo1').click(function(e) {
  if(e.ctrlKey  == true) {
    alert("control click");
  } 
  else {
    alert("normal click");
        $("#demo1").bind('select_node.jstree', function(event, data) {
        var url = data.rslt.obj.children("a:eq(0)").attr("href"); 
        $('.ui-layout-center').load(url);
        });
  } 
}); 

3 个答案:

答案 0 :(得分:2)

检查e.ctrlKey

答案 1 :(得分:1)

if ( e.ctrlKey || e.metaKey )
{
   /* do your click thing (e.g. open-in-new-window) */
   window.open( $(this).attr('data-url') );
   return;
}
else
{
   /* do your regular thing (e.g. go to another page) */
   window.location.href = $(this).attr('data-url');
}

对于绑定部分,可能是e.preventDefault();帮助

并且:在上面的代码中尝试 return false ,以防止事件'冒泡'。

答案 2 :(得分:0)

我绝对不是那么熟悉(最近才开始使用jquery)但是会阻止默认和http://plugins.jquery.com/plugin-tags/ctrl-click帮助你吗?

相关问题