2015-04-11 5 views
0

Я пытаюсь открыть диалог при нажатии кнопки ввода. Но это не открытие диалога, просто скрывающего текст. Может кто-нибудь объяснить, почему?Почему диалоговое окно JQuery не открывается?

<!doctype html> 
 
<html lang="en"> 
 
<head> 
 
    <meta charset="utf-8"> 
 
    <title>jQuery UI Dialog - Default functionality</title> 
 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
    <link rel="stylesheet" href="/resources/demos/style.css"> 
 

 
</head> 
 
<body> 
 

 
<script> 
 

 
    $(document).keydown(function(mykey2){ 
 
     if(mykey2.which == 13){ 
 
      $("#dialog").dialog(); 
 
     } 
 
    }); 
 

 
    
 
</script> 
 

 
<div id="dialog" title="Basic dialog"> 
 
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p> 
 
</div> 
 

 

 
</body> 
 
</html>

Я не understang, что это неправильно.

+0

попробуйте добавить 'HTTP:' 'перед //code..'s? –

+0

Я думаю, что это проблема с версией, работает ** [Здесь] (http://jsfiddle.net/wjgahkLk/1/) **, но не с вашей версией ** [Здесь] (http://jsfiddle.net/ wjgahkLk/2 /) ** –

+0

О да, это тоже верно –

ответ

0

Кажется, вам нужно отменить нажатие клавиши ввода.

$(document).keydown(function(event) { 
 
     if (event.keyCode == 13) { 
 
     $("#dialog").dialog(); 
 
     event.preventDefault(); 
 
     } 
 
    });
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
<link rel="stylesheet" href="/resources/demos/style.css"> 
 
<div id="dialog" title="Basic dialog" style="display:none"> 
 
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p> 
 
</div>

+0

Это сработало. Thanx! –

Смежные вопросы