2014-12-04 33 views
1

我想我的網站上的第一件事是要求輸入密碼的對話框,如果密碼長度小於6,稱爲密碼錯誤的跨度顯示,並且您不被允許繼續。如果密碼長度大於或等於6,則可以按確定並繼續。我的問題是沒有任何顯示,並且無論密碼的長度是多少,我都無法繼續。這裏是我的代碼:莫代爾將不會關閉使用確定按鈕

<div class="password_insert" title="Set your password"> 
    <span id="error"><b>Passwords error!</b></span> 
    <span>New Password: </span> 
    <br /> 
    <input type="password" id="ins_pass" /> <span>Repeat Password: </span> 
    <br /> 
    <input type="password" id="rep_pass" /> 
</div> 

<script> 
$(function() { 
    $(".password_insert").dialog({ 
     modal: true, 
     buttons: { 
      Ok: function() { 
       $(this).dialog("close"); 
      } 
     }, 
     beforeClose: function (event, ui) { 
      var x = $('#ins_pass').val(); 
      var y = x.length(); 
      if (x < 6) { 
       $("#error").show(); 
       event.preventDefault(); 
      } 
     } 
    }); 
}); 
</script> 

Demo

+0

控制檯錯誤? jQuery加載正確嗎? – isherwood 2014-12-04 21:31:15

+0

偏題:你的'
'標籤格式不正確。 – isherwood 2014-12-04 21:32:08

+0

我的意思是對話框顯示,但沒有任何反應,當我按下確定,無論輸入密碼的長度是多少。另外:跨度隱藏在開頭,但我沒有把風格標籤放在我的問題:)。 – mouseepaad 2014-12-04 21:32:28

回答

1

瀏覽器控制檯報告以下錯誤:

Uncaught TypeError: number is not a function 

您使用的是length方法不正確:

var y = x.length(); 

var y = x.length; 

Demo

另外,題外話:使用標籤for屬性,而不是span標籤的可訪問性。

+0

小提琴更新爲隱藏錯誤負載。 – isherwood 2014-12-04 21:37:34

+0

好的,我修好了。非常感謝你的回答:),你太棒了! :) – mouseepaad 2014-12-04 21:39:21