Jquery UI dialog not working along side JQuery Mobile

早过忘川 提交于 2019-11-28 12:38:35

问题


I cannot get a simple dialog box working in JQuery when I also include JQuery mobile:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Dialog - Default functionality</title>


  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>


  <script>
  $( function() {
    $( "#dialog" ).dialog();
  } );
  </script>
</head>
<body  style="background-color: #888">

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

I have looked at these previous questions which do not seem to help:

  • jquery mobile dialog not working
  • Incompatible jquery mobile and ui

What am I doing wrong?


回答1:


After reading the post Using multiple versions of jquery ui from RedNao i was able to create a simple proof of concept.

The idea is to swap two instances of jQuery but, you are warned, i haven't fully tested against heavy usage in code.

After that, i'm hiding the UI dialog markup to jQuery Mobile by using data-enhance="false".

<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
   var jQM=jQuery, $QM=$;
</script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
  var jQUI=jQuery, $QUI=$;
  window.jQuery = jQM;
  window.$ = $QM;
  $(document).on('mobileinit', function () {
    $.mobile.ignoreContentEnabled = true;
  });

</script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

Then, it looks like this:

Plunker: https://plnkr.co/edit/oOg6cKEuMFXVrMn3ntCb?p=preview



来源:https://stackoverflow.com/questions/41102490/jquery-ui-dialog-not-working-along-side-jquery-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!