Jquery UI dialog not working along side JQuery Mob

2020-02-15 09:34发布

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:

What am I doing wrong?

1条回答
Ridiculous、
2楼-- · 2020-02-15 09:52

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:

enter image description here

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

查看更多
登录 后发表回答