當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


jQuery UI Dialog autoOpen用法及代碼示例


“自動打開”選項指示在初始加載頁麵時是否應自動打開對話框。默認情況下,值是true。

用法:

$( ".selector" ).dialog({
  autoOpen:false
});

方法:首先,添加項目所需的jQuery UI腳本。

<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:



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> 
        $(function () { 
            $("#gfg").dialog({ 
                autoOpen:true, 
            }); 
            $("#geeks").click(function () { 
                $("#gfg").dialog("open"); 
            }); 
        }); 
    </script> 
</head> 
  
<body> 
    <div id="gfg" title="GeeksforGeeks"> 
        jquery UI| autoOpen dialog option 
    </div> 
      
    <button id="geeks">Open Dialog</button> 
</body> 
  
</html>

輸出:

範例2:

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> 
        $(function () { 
            $("#gfg").dialog({ 
                autoOpen:false, 
            }); 
            $("#geeks").click(function () { 
                $("#gfg").dialog("open"); 
            }); 
        }); 
    </script> 
</head> 
  
<body> 
    <div id="gfg" title="GeeksforGeeks"> 
        Jquery UI| autoOpen dialog option 
    </div> 
      
    <button id="geeks">Open Dialog</button> 
</body> 
  
</html>

輸出:




相關用法


注:本文由純淨天空篩選整理自taran910大神的英文原創作品 jQuery UI Dialog autoOpen Option。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。