弹出框仅在我第三次打开时起作用吗?

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

我有一个弹出窗口,我打算让它的功能是使用交互式日历打开,该日历允许用户使用jquery datepicker输入开始日期和结束日期。但是当前在页面加载中,我必须打开和关闭弹出窗口两次,然后弹出窗口才能按预期运行,我想知道为什么会发生这种情况/如何解决?这是代码

相关网页

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <title> {(BnB)} Market </title>
  </head>

<div id= 'user_listings'>
 </div>
 <body>
 Market BnB
 </body>
<a href = '/make_listings' > Looking to show your own listing? </a>
<div id = 'table'>
<table>
  <tr>
  <h1> BnB-able properties </h1>
  </tr> 
  <% @BnB.each do |record| %>
  <tr>
     <td class ='new_BnB'><%= record['address'] %> </td>
    <td class ='code_BnB'> | <%= record['post_code']%> </td>
    <br>

       <a id="OpenDialog" href="#">  <img src = <%= record['photo'] %> width="300" height="200" alt='test' >
    </a> 
    <div id="dialog" title="Property Info" style="display: none;" >
    <p>
<p>Start date: <input type="text" id="datepicker"> End date: <input type="text" id="datepicker2"></p>
 <input type = "submit" value='Submit'>
</p>

    </div>

    </tr>

    </table>
    <% end %>

    <head>

    <head>
<title></title>
</head>
<body>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

</body>

  <%# <title>jQuery UI Datepicker - 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>

</head>

  <script src="interface.js"></script>

</div>

interface.js

 $(document).ready(function() {
    $("#OpenDialog").click(function () {
     $("#dialog").dialog({modal: true, height: 500, width: 700 });
   });
 });

  $( function() {
    $( "#datepicker" ).datepicker();
  } );
  $( function() {
    $( "#datepicker2" ).datepicker();
  } );

** @BnB值是**

require 'pg'

class BnBControl

  attr_accessor :connection

  def self.all
    @connection = PG.connect(dbname: 'bnb')

    listings = @connection.exec("SELECT * FROM properties")
  end
------
class BnB < Sinatra::Base
  enable :sessions

  get '/' do
    #if session[:user] 

      @BnB = BnBControl.all 

      erb :index_logged_in 
    # else
    #   erb :index
    # end
  end

这些是单独的文件,仅包含在相同的代码围栏中

javascript jquery html ruby erb
1个回答
0
投票

您使用document.ready$(function()相同,不需要多次使用。另外,请在弹出单击事件处理程序之前在$(document).ready中调用datepicker函数,该函数应该对您有用。

尝试以下

$(document).ready(function() {
    $( "#datepicker" ).datepicker();
    $( "#datepicker2" ).datepicker();
    $("#OpenDialog").click(function () {
     $("#dialog").dialog({modal: true, height: 500, width: 700 });
   });
});
© www.soinside.com 2019 - 2024. All rights reserved.