2011-06-26 78 views

回答

0

從鏈路上的例子,你可以修改腳本更改元素切換

<style> 
#feedback { font-size: 1.4em; } 
#selectable .ui-selecting { background: #FECA40; } 
#selectable .ui-selected { background: #F39814; color: white; } 
#selectable { list-style-type: none; margin: 0; padding: 0; } 
#selectable li { margin: 3px; padding: 1px; float: left; width: 100px; height: 80px; font-size: 4em; text-align: center; } 
</style> 
<script> 
$(function() { 
    $('#selectable li').bind('mouseup', function(e) { 
     $(e.target).removeClass('ui-selecting'); 
     var selected = $(e.target).attr('data-selected'); 
     if (selected) { 
      $(e.target).attr('data-selected', null); 
     } else { 
      $(e.target).addClass('ui-selected'); 
      $(e.target).attr('data-selected', true); 
     } 
    }); 
    $('#selectable li').bind('mousedown', function(e) { 
     $(e.target).removeClass('ui-selected'); 
     $(e.target).addClass('ui-selecting'); 
    }); 
}); 
</script> 
1

您可以在鼠標按下設置metaKey模擬按Ctrl被壓:

$('#selectable').bind("mousedown", function(e) { 
    e.metaKey = true; 
}).selectable()​;​ 

請參閱DEMO

相關問題