2017-09-28 120 views
0

我想使用jquery-modal,並用buttonclick來喚起它。但是,當我這樣做,我得到jquery-modal打開按鈕

Uncaught TypeError: Cannot read property 'blur' of undefined 

HTML &的JavaScript

<button>Button</button> 
... 
<form id="login-form" class="modal"> 
    <div>Test</div> 
</form> 
... 
$('button').click(function() { 
    $('#login-form').modal(); 
}); 

回答

0

你嘗試過這樣的代碼:

$(document).ready(function(){ 
    $('button').click(function() { 
     $('#login-form').modal(); 
    }); 
}); 
+0

我已經使用 '(函數($){ ... })(jQuery的);' –

+0

你能在這裏把完整的代碼,請。 –

+0

https://pastebin.com/ZVybfbm1 jquery.modal.css和jquery.modal.js是https://github.com/kylefox/jquery-modal 模式工作,當我點擊鏈接,而是錯誤當點擊按鈕 –

0

你可以給ID爲按鈕,並使用該ID觸發點擊事件。

<button id="loginButton">Button</button> 

$('#loginButton').click(function() { 
    $('#login-form').modal(); 
}); 
+0

這不是選擇器問題,它的工作很好 –