2017-11-25 164 views
0

我正在制作一个网络应用程序,它为用户输入的德语名词提供了文章。 我写过代码,用户将接受名词,数据库中的文章将显示在模式框中。 但模态框不留。此外,我第一次单击提交按钮时,即使数据库中存在单词,else部分也会运行。模态框上点击提交按钮

下面的代码:

<!-- Parallax Image with noun Text --> 
 
<div class="bgimg-2 w3-display-container w3-opacity-min"> 
 
    <div class="w3-display-middle"> 
 
    <span class="w3-xxlarge w3-text-white w3-wide">NOUN</span> 
 
    </div> 
 
</div> 
 
<!-- Container (noun Section) --> 
 
<div class="w3-content w3-container w3-padding-64" id="noun"> 
 
    <h3 class="w3-center">ENTER THE NOUN: </h3></br></br> 
 
    <form name="logged_in.jsp" method="post" action=""> 
 
    <div class="w3-center"> 
 
      <input type="text" name="noun"></br></br></br> 
 
    </div> 
 

 
    
 
    
 
    <div class="w3-center"> 
 
    <button class="w3-button w3-black w3-right w3-section" type="submit" id="article" > 
 
      GET ARTICLE 
 
     </button> 
 
    </div> 
 
    </form> 
 
    
 
</div> 
 

 

 
<!-- The Modal --> 
 
<div id="nounModal" class="modal"> 
 
    <% String s =null; 
 
     String s1=request.getParameter("noun"); 
 
      String s2 =null; 
 
      String s3 =null; 
 
      int f=0; 
 
     try{ 
 
     System.out.println(s1); 
 
      Statement st = con.createStatement(); 
 
      ResultSet rs = st.executeQuery("select * from nouns where noun='"+s1+"'"); 
 
      
 
      if(rs.next()){ 
 
       f=1; 
 
      s=rs.getString("article"); 
 
      s2=rs.getString("plural"); 
 
      s3=rs.getString("meaning"); 
 
      } 
 
     }catch(Exception e){System.out.println("e.............."+e);} 
 
    
 
     if(f==1){%> 
 
     
 

 
     <div class="modal-content"> 
 
      <button type="button" class="close" data-dismiss="modal">Close</button> 
 
      <div id="output"> 
 
       <p>Article: <%=s%></br></p> 
 
      <p>Noun: <%=s1%></br></p> 
 
      <p>Plural: <%=s2%></br></p> 
 
      <p>Meaning: <%=s3%></p> 
 
      
 
      </div> 
 
    <%} 
 
    else{%> 
 
    <div class="modal-content"> 
 
      <button type="button" class="close" data-dismiss="modal">Close</button> 
 
      <p>Sorry! no results found. 
 
       would you like to add a new word? <a>add</a> click here 
 
      </p> 
 
       
 
      
 
    <%}%> 
 
    
 
    </div > 
 

 
</div> 
 

 
<script> 
 

 
$(document).ready(function(){ 
 
    $("#article").click(function(){ 
 
     $("#nounModal").modal(''); 
 
    }); 
 
\t 
 
\t </script>

+0

我可以看到** Peter **已经要求编辑这个问题,所以我希望他能阅读这个。我会建议你清理源代码,使你的编辑建议值得接受。对标题进行小修改而不清理主要问题内容是不值得接受的。 – NewToJS

回答

0

你的按钮都应包含数据切换= “莫代尔” 数据目标= “#nounModal” atributes。

<button class="w3-button w3-black w3-right w3-section" type="submit" id="article" data-toggle="modal" data-target="#nounModal">GET ARTICLE </button> 

或尝试$(“#nounModal”)。modal('show');