對話框是通知用戶某些信息的方法。這是在用戶窗口上彈出以顯示下一步將發生的信息或開發人員想要向用戶澄清的任何信息的一種好方法。 jQueryUI對話框方法用於在頁麵內部創建基本的對話框窗口。它具有標題欄和內容區域,默認情況下可以使用“ X”圖標進行移動,調整大小和關閉。當對話框獲得焦點時,將觸發焦點事件。
用法:
$(".selector").dialog (
   focused:function( event, ui ) {
       console.log('focused')
   }, 
CDN鏈接:首先,添加項目所需的jQuery Mobile腳本。
<link href = “https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel =”stylesheet”>
<script src = “https://code.jquery.com/jquery-1.10.2.js”></script>
<script src = “https://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>
範例1:
- “打開對話框”按鈕將觸發點擊函數(#gfg),該函數將在對話框(#gfg2)中進一步打開‘textarea’。
 - focus(event,ui):觸發框獲得焦點。此焦點具有附加的回調函數。
事件:類型->事件ui:類型->對象
回調函數:function(event,ui){console.log(‘focused’)}
 
HTML
<!DOCTYPE html> 
<html lang="en"> 
  <head> 
    <meta charset="utf-8" /> 
    <link href= 
"https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
      rel="stylesheet"/> 
    <script src= 
"https://code.jquery.com/jquery-1.10.2.js"> 
    </script> 
    <script src= 
"https://code.jquery.com/ui/1.10.4/jquery-ui.js"> 
    </script> 
    <script type="text/javascript"> 
      $(function () { 
        $("#gfg2").dialog({ 
          autoOpen:false, 
          focus:function (event, ui) { 
            console.log("focused"); 
          }, 
        }); 
        $("#gfg").click(function () { 
          $("#gfg2").dialog("open"); 
        }); 
      }); 
    </script> 
  </head> 
  <body> 
    <div id="gfg2" title="GeeksforGeeks"> 
      <textarea>jQuery UI | focus(event, ui) Event</textarea> 
    </div> 
    <button id="gfg">Open Dialog</button> 
  </body> 
</html>輸出:

參考:https://api.jqueryui.com/1.9/dialog/#event-focus
相關用法
- jQuery UI dialog resizeStart(event, ui)用法及代碼示例
 - jQuery UI dialog dragStop(event, ui)用法及代碼示例
 - jQuery UI dialog dragStart(event, ui)用法及代碼示例
 - jQuery UI dialog create(event, ui)用法及代碼示例
 - jQuery UI dialog close(event, ui)用法及代碼示例
 - jQuery UI dialog resize(event,ui)用法及代碼示例
 - jQuery UI dialog open(event,ui)用法及代碼示例
 - jQuery UI dialog resizeStop()用法及代碼示例
 - jQuery UI Dialog closeOnEscape用法及代碼示例
 - jQuery UI Dialog closeText用法及代碼示例
 - jQuery UI Dialog draggable用法及代碼示例
 - jQuery UI Dialog height用法及代碼示例
 - jQuery UI Dialog minHeight用法及代碼示例
 - jQuery UI Dialog title用法及代碼示例
 - jQuery UI Dialog maxHeight用法及代碼示例
 - jQuery UI dialog option()用法及代碼示例
 - jQuery UI dialog open()用法及代碼示例
 - jQuery UI Dialog resizable用法及代碼示例
 - jQuery UI Dialog modal用法及代碼示例
 
注:本文由純淨天空篩選整理自taran910大神的英文原創作品 jQuery UI dialog focus(event,ui) Event。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
