2016-04-02 41 views
0

當我單擊密碼textbox時,出現tooltip出現問題。任何人有任何建議爲什麼jquery代碼不起作用?單擊文本框時出現提示框

   <div class="form-group"> 

       <input type="password" name="password" id="password" tabindex="1" class="form-control" placeholder="Password" required /> 

        </div> 

     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> <!--jquery--> 

         <script> 

         $(document).ready(function() { 

        $('#password').on({ 
            "click": function() { 
              $(this).tooltip({ items: "#password", content: "Displaying on click"}); 
              $(this).tooltip("open"); 
                 }, 
               "mouseout": function() {  
               $(this).tooltip("disable"); 
                      } 
                       }); 

          }); 


        </script> 
+0

嘗試更換'$(本).tooltip( 「禁止」);用'$(本).tooltip'( 「親密」);'看看會發生什麼。 – TechnoCF

+0

嗨TechnoCF似乎沒有執行時,我用我的替換。 – steve

+0

這個想法是一個工具提示,顯示用戶的消息,他們的密碼必須是某些字符等 – steve

回答

0

tooltip不是jQuery庫的一部分。你需要包含jquery ui。此外,您需要確保tooltip在嘗試禁用之前已初始化。

<html> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
<script> 
    $(document).ready(function() { 
     var hasToolTip =false; 
     $('#password').on({ 
      "click": function() { 
       hasToolTip = true; 
       $(this).tooltip({ items: "#password", content: "Displaying on click"}); 
       $(this).tooltip("open"); 
      }, 
      "mouseout": function() {  
       if(hasToolTip) 
       { 
        $(this).tooltip("disable"); 
        hasToolTip = false; 
       }             
      } 
     }); 
    }); 

</script> 
<body> 
    <div class="form-group"> 
     <input type="password" name="password" id="password" tabindex="1" class="form-control" placeholder="Password" required /> 
    </div> 
</body> 

https://jqueryui.com/tooltip/

+0

沒有歡樂 - gmfm。還是行不通。 – steve

+0

編輯回答以顯示工作代碼並糾正初始化錯誤。 – gmfm

+0

非常感謝gmfm!得到它的工作:) – steve