简体   繁体   English

单击按钮时页面显示所有语义UI模式

[英]Page shows all Semantic UI modals when button clicked

I'm trying to have a popup for the description of a book when a user clicks the "view details" button, and I am trying to accomplish that using the semantic ui modal. 当用户单击“查看详细信息”按钮时,我试图弹出一本书的描述,并且尝试使用语义ui模式来实现这一点。 Because I have several books to render, I am using an ejs loop to loop through all the data at once, but every time I click on the button, all of the modals show up, instead of just the one book description. 因为我要渲染几本书,所以我使用ejs循环一次遍历所有数据,但是每次单击按钮时,都会显示所有模态,而不仅仅是一本书的描述。

Here is my ejs code 这是我的ejs代码

<% include header.ejs %>
<% include nav.ejs %>
<div class="page-hero" style="background-image: url('a.jpg'); width: 100%;">
<h1 id="eachTitle">ADD BOOK</h1>
</div>
<div class="ui container">
<form method="POST">
    <input type="text" name="search" placeholder="Search..." required class="searchBook">
    <input type="submit" class="ui button basic blue"value="Search">
</form>
<iframe name="target" style="display: none;"></iframe>
<% for(var i = 0; i < results.length; i++){ %>
    <div class="ui grid">
        <div class="column four wide">
            <form method="POST" action="">
            <div class="ui card">
                <div class="image">
                    <input value="<%= results[i].thumbnail %>" name="image" style="display: none">
                    <img src = "<%= results[i].thumbnail %>"/>
                </div>
                <div class="content">
                    <div class="header">
                        <input class="ui small header title" value="<%= results[i].title %>" readonly name="title">
                    </div>
                    <div class="meta">
                        <div class="des">Author:<input class="desc" value="<%= results[i].authors %>" readonly name="author"></div><br>
                        <div class="des">Published on:<input class="desc" value="<%= results[i].publishedDate %>" readonly name="date"></div><br>
                        <div class="des">Pages:<input class="desc" value="<%= results[i].pageCount %>" readonly name="pages"></div><br>
                        <div class="des">Rating:<input class="desc" value="<%= results[i].averageRating %>" readonly name="rating" style="display: none">
                            <div class="star-ratings-css">
                                <div class="star-ratings-css-top" style="width: <%= results[i].averageRating * 26.5 + "%" %>"><span>★</span><span>★</span><span>★</span><span>★</span><span>★</span></div>
                                <div class="star-ratings-css-bottom"><span>★</span><span>★</span><span>★</span><span>★</span><span>★</span></div>
                            </div>
                        </div><br>
                    </div>
                </div>
                <div id="modaldiv" class="ui modal" style="position: relative">
                        <i class="close icon"></i>
                        <div class="header"><%=results[i].title%></div>
                        <div class="content">
                            <input value="<%= results[i].description%>" readonly style="display: none" name=description>
                            <%= results[i].description%>
                        </div>
                    </div><!-- Should be out side of the book info div -->
                <div class="content extra">
                    <a class="ui button basic fluid detail">View Detail</a>
                    <button class="add ui button basic fluid" type="submit" name="button" id="<%= results[i].title %>">Add</button>
                </div>
            </div>
        </div>
    </div> 
</form>
<% } %>
</div>
<% include footer.ejs%>
<script type="text/javascript">
  $(document).ready(function(){
      $(document).on('click', ".detail", function(){
          $(".ui.modal").modal("show");
      })
  })
</script>
</body>
</html>

Does anyone know a way that I can stop this from happening? 有谁知道我可以阻止这种情况发生的方法?

You have a problem with the name of the modal in your loop. 您的循环中的模态名称有问题。 It's all time the same so when you call it here : 时间都是一样的,所以当您在这里调用它时:

$(".ui.modal").modal("show"); $( “ui.modal。 ”)模式(“ 秀”)。

All your modals have the same name, so all the modal just show themselves. 您所有的模态都具有相同的名称,因此所有模态只显示自己。

Give their an unique name, and call the unique name. 给他们一个唯一的名字,然后叫这个唯一的名字。

For exemple : 举个例子 :

<div class="ui modal"+<% loop.index %> style="position: relative">

And you can call it : 你可以这样称呼:

$(".ui.modal.(loop.index)").modal("show");

On this way, you will call only one of your modal, just play with the classname or the id. 这样,您将只调用一种模式,仅使用类名或ID进行播放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM