JQuery对话框只工作一次

问题描述 投票:1回答:1

如果有人比我更了解JQuery,请告诉我为什么在这个测试代码中,第一个对话框能用,而第二个不能用。谢谢。

<!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">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#dialog" ).dialog();
  } );
  </script>
</head>
<body>
<?php 
    $txt="This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.";
    $txt2="This is a second box.";?>
<!-- ***** First use ***** -->
<div id="dialog" title="Basic dialog">
  <p><?php echo $txt?></p>
    </div>
<!-- ***** Second Use ***** -->
<div id="dialog" title="Basic dialog">
  <p><?php echo $txt2?></p>
</div>
</body>
</html>
jquery alert
1个回答
0
投票

JQuery的Id必须是唯一的 你用了两个相同的id。那么为什么它不能工作。试试用不同的Id,比如id="dialog,第二个id="dialog1。

© www.soinside.com 2019 - 2024. All rights reserved.