最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Displaying popup with flask and jquery - Stack Overflow

matteradmin9PV0评论

on my website after clicking button I want to display new form which will allow users to add opinion. Im not sure in which way I should add jquery script to my project. I tried to it on simple html site and it works, but I couldnt do the same with flask app. Here is my code:

% extends "bootstrap/base.html" %}

{% block content %}

<link rel="stylesheet" href=".css">
<script src=" ajax/libs/jquery/1/jquery.js"></script>

 <script src=".js"></script>
 <script type="text/javascript">

$(function () {
  $("#btnclick").click(function () {
    $("#divpopup").dialog({
      title:"Dodaj opinie",
      width: 430,
      height: 200,
      modal:true,
      buttons: {
        Close:
        function(){
          $(this).dialog('close');
        }
      }
    });

  });
})

<div id="divpopup" style="display: none">
Here will be form
</div>

 <button type="button" id="btnclick">Add opinion</button>

{% endblock %}

And after clicking on the button nothing happend. I use bootstrap and jinja2, so should I use other contents to add scripts?

on my website after clicking button I want to display new form which will allow users to add opinion. Im not sure in which way I should add jquery script to my project. I tried to it on simple html site and it works, but I couldnt do the same with flask app. Here is my code:

% extends "bootstrap/base.html" %}

{% block content %}

<link rel="stylesheet" href="http://ajax.googleapis./ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
<script src="http://ajax.googleapis. ajax/libs/jquery/1/jquery.js"></script>

 <script src="http://ajax.googleapis./ajax/libs/jqueryui/1/jquery-ui.js"></script>
 <script type="text/javascript">

$(function () {
  $("#btnclick").click(function () {
    $("#divpopup").dialog({
      title:"Dodaj opinie",
      width: 430,
      height: 200,
      modal:true,
      buttons: {
        Close:
        function(){
          $(this).dialog('close');
        }
      }
    });

  });
})

<div id="divpopup" style="display: none">
Here will be form
</div>

 <button type="button" id="btnclick">Add opinion</button>

{% endblock %}

And after clicking on the button nothing happend. I use bootstrap and jinja2, so should I use other contents to add scripts?

Share Improve this question edited Nov 19, 2018 at 16:59 davidism 128k31 gold badges415 silver badges347 bronze badges asked Nov 19, 2018 at 15:51 FrendomFrendom 55811 silver badges34 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You might consider using a Bootstrap Modal for this as you said you're using Bootstrap in the project.

This is a very simple example copied from their website:

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        INSERT FORM HERE
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

If you're using Bootstrap 4 you should be able to copy this right in and change the IDs to match what you want. Link to documentation: https://getbootstrap./docs/4.0/ponents/modal/

Post a comment

comment list (0)

  1. No comments so far