【问题标题】:How can I get the confirmation box to work with jsp?如何让确认框与 jsp 一起使用?
【发布时间】:2020-05-27 05:39:13
【问题描述】:

所以每次我想从数据库中删除一条记录时,我都想显示一个确认框,该框显示成功,但问题是无论我点击“确定”还是“取消”,记录都在删除

如何让它工作?谢谢

这是我的代码:

                         <table>
                                   <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>Date RDV</th>
                                            <th>Motif</th>
                                            <th>ID Patient</th>
                                            <th>Action</th>
                                        </tr>


                                        </thead>
                                        <p:forEach items="${liste }" var = "rdv">
                                    <tbody>

                                        <tr>
                                            <td>${rdv.id_Rdv }</td>
                                            <td>${rdv.date_Rdv }</td>
                                            <td>${rdv.motif }</td>
                                            <td>${rdv.id_P }</td>

                                            <td>
                                            <a href="${pageContext.request.contextPath}/RDVController?action=supprimer&Id_Rdv=${rdv.id_Rdv }" onclick="confirmation()" > Supprimer</a>
                                            </td>

                                        </tr>

                                    </tbody>                                                                              
                                  </p:forEach>                                       
                            </table>

这是我的 javascript 代码:

    function confirmation(){

    var result = confirm("vous êtes sûr ?");

    if(result){
        return true;
    }
    else{
        return false;
    }
}

【问题讨论】:

    标签: javascript jsp servlets


    【解决方案1】:

    您可以使用button 代替a 标记并将css 应用于按钮,使其看起来像a 标记。在这里,在下面的代码中,每当您单击button 时,如果单击是,则会打开弹出窗口,然后页面将直接重定向,否则页面将保留在同一页面上。

    function confirmation(button) {
      //getting href value
      var href = button.getAttribute("href");
      console.log(href);
      var result = confirm("vous êtes sûr ?");
    
      if (result) {
        //if click yes redirect 
        window.location.href = href;
      } else {
    
        return false;
      }
    }
    .supprimer {
      background-color: transparent;
      text-decoration: underline;
      border: none;
      color: blue;
      cursor: pointer;
    }
    
    supprimer:focus {
      outline: none;
    }
    <table>
      <thead>
        <tr>
          <th>ID</th>
          <th>Date RDV</th>
          <th>Motif</th>
          <th>ID Patient</th>
          <th>Action</th>
        </tr>
    
    
      </thead>
      <p:forEach items="${liste }" var="rdv">
        <tbody>
    
          <tr>
            <td>${rdv.id_Rdv }</td>
            <td>${rdv.date_Rdv }</td>
            <td>${rdv.motif }</td>
            <td>${rdv.id_P }</td>
    
            <td>
              <button class="supprimer" href="${pageContext.request.contextPath}/RDVController?action=supprimer&Id_Rdv=${rdv.id_Rdv }" onclick="confirmation(this)"> Supprimer</button>
    
            </td>
    
          </tr>
    
        </tbody>
      </p:forEach>
    </table>

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多