jQuery - 可選擇互動



描述

Selectable 函式可以與 jQuery UI 中的互動一起使用。此函式可以在任何 DOM 元素上啟用 selectable 功能。使用游標繪製方框以選擇專案。按住 Ctrl 鍵可以進行多個不相鄰的選擇。

語法

以下是使用可拖動功能的簡單語法:

$( "#selectable" ).selectable();

示例

以下是一個簡單的示例,展示了 selectable 的用法:

<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <title>jQuery UI Selectable - Default functionality</title>
  
      <link rel = "stylesheet" 
         href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  
      <script type = "text/javascript" 
         src = "https://tutorialspoint.tw/jquery/jquery-3.6.0.js">
      </script>
		
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js">
      </script>

      <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; width: 60%; }
         #selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
      </style>
		
      <script>
         $(function() {
            $( "#selectable" ).selectable();
         });
      </script>
   </head>

   <body>
 
      <ol id = "selectable">
         <li class = "ui-widget-content">Item 1</li>
         <li class = "ui-widget-content">Item 2</li>
         <li class = "ui-widget-content">Item 3</li>
         <li class = "ui-widget-content">Item 4</li>
         <li class = "ui-widget-content">Item 5</li>
         <li class = "ui-widget-content">Item 6</li>
         <li class = "ui-widget-content">Item 7</li>
      </ol>
 
   </body>
</html>

這將產生以下結果:

jquery-interactions.htm
廣告
© . All rights reserved.