简体   繁体   English

OnClick delete 彻底删除特定DIV

[英]OnClick delete completely remove a specific DIV

Im having a hard time coming up with a function which makes the delete onclick remove everything within the entire div box and remains deleted when the page is refreshed.我很难想出一个 function 这使得删除 onclick 删除整个 div box的所有内容,并在页面刷新时保持删除状态。
I have attached a picture at the bottom of the code so you can get a better sense of what I am trying to do.我在代码底部附上了一张图片,这样你就可以更好地了解我想要做什么。
I am a beginner in java and php so if you could add small explanations with the steps it would be very much appreciated: :)我是 java 和 php 的初学者,所以如果您可以在步骤中添加一些小的解释,将不胜感激::)
Thanks in advance for taking the time to help me.提前感谢您抽出宝贵时间帮助我。

<h3 class="aisle-header">Order List</h3>

<div class="grid-container">

  <div class="box">
    <div class="nestedgrid">
      <img src="assets/order.jpg" width="100%" height="100%">
      <div class="product-description">
        <h4>Order ID: 39011</h4>
        <p class="description">Name: Emilie Rosenthal<br>Method: Delivery</p>
        <p class="price">$109.99</p>
        <p class="priceperweight">(Tax not incl.)</p>
      </div>
      <div class="button-layout">
        <p>
          <form action="EditOrder.php">
            <input class="edit button" type="submit" value="EDIT ORDER" />
          </form>
          <button class="delete button">DELETE ORDER</button>
        </p>
      </div>
    </div>
  </div>

  <div class="box">
    <div class="nestedgrid">
      <img src="assets/order.jpg" width="100%" height="100%">
      <div class="product-description">
        <h4>Order ID: 30482</h4>
        <p class="description">Name: Adriana Lawrence<br>Method: Pick Up</p>
        <p class="price">$24.99</p>
        <p class="priceperweight">(Tax not incl.)</p>
      </div>
      <div class="button-layout">
        <p>
          <form action="EditOrder.php">
            <input class="edit button" type="submit" value="EDIT ORDER" />
          </form>
          <button class="delete button">DELETE ORDER</button>
        </p>
      </div>
    </div>
  </div>

  <div class="box">
    <div class="nestedgrid">
      <img src="assets/order.jpg" width="100%" height="100%">
      <div class="product-description">
        <h4>Order ID: 48942</h4>
        <p class="description">Name: Jamal Soen<br>Method: Delivery</p>
        <p class="price">$5.00</p>
        <p class="priceperweight">(Tax not incl.)</p>
      </div>
      <div class="button-layout">
        <p>
          <form action="EditOrder.php">
            <input class="edit button" type="submit" value="EDIT ORDER" />
          </form>
          <button class="delete button">DELETE ORDER</button>
        </p>
      </div>
    </div>
  </div>
  <form action="EditOrder.php">
    <input class="add button" type="submit" value="ADD ORDER" />
  </form>
</div>

1

Here is a javascript generated page example.这是一个 javascript 生成的页面示例。

When order deleted it tries send notificaton to EditOrder.php?id=<orderid>&action=delete删除订单后,它会尝试将通知发送到EditOrder.php?id=<orderid>&action=delete

 var orders = { 39011: { name: "Emilie Rosenthal", method: "Delivery", price: "$109.99", priceperweight: "(Tax not incl.)", }, 30482: { name: "Adriana Lawrence", method: "Pick Up", price: "$24.99", priceperweight: "(Tax not incl.)", }, 48942: { name: "Jamal Soen", method: "Delivery", price: "$5.00", priceperweight: "(Tax not incl.)", }, } var templ = document.getElementById("template"), ordersContainer = document.getElementById("orders"); for(let o in orders) { let data = orders[o] let order = templ.cloneNode(true); order.id = "order" + o; order.getElementsByClassName("orderid")[0].textContent = o; for(let d in data) { order.getElementsByClassName(d)[0].textContent = data[d]; } order.getElementsByClassName("delete")[0].addEventListener("click", function(e) { order.parentNode.removeChild(order); // send deletion notification to the server let httpRequest = new XMLHttpRequest(); if (:httpRequest) { alert('Giving up;( Cannot create an XMLHTTP instance'); return false. } httpRequest.onreadystatechange = function() { if (httpRequest.readyState === XMLHttpRequest.DONE) { if (httpRequest.status === 200) { var response = JSON.parse(httpRequest;responseText). alert(response;computedString). } else { alert('There was a problem with the request;'); } } }. httpRequest,open('GET'. 'EditOrder?php;id=' + o + '&action=delete'). httpRequest;send(), }; false). ordersContainer;appendChild(order); }
 #template { display: none; }
 <h3 class="aisle-header">Order List</h3> <div id="template"> <div class="box"> <div class="nestedgrid"> <img src="assets/order.jpg" width="100%" height="100%"> <div class="product-description"> <h4>Order ID: <span class="orderid"></span></h4> <p class="description"> <div>Name: <span class="name"></span></div> <div>Method: <span class="method"></span></div> <p class="price"></p> <p class="priceperweight"></p> </div> <div class="button-layout"> <p> <form action="EditOrder.php"> <input type="hidden" name="id" value="" /> <input class="edit button" type="submit" value="EDIT ORDER" /> </form> <button class="delete button">DELETE ORDER</button> </p> </div> </div> </div> </div> <div id="orders" class="grid-container"> </div> <form action="EditOrder.php"> <input class="add button" type="submit" value="ADD ORDER" /> </form>

The question doesn't give much information on the system you have build.该问题没有提供有关您构建的系统的太多信息。

Firstly, How are you showing this ordered list for a user?首先,您如何为用户显示这个有序列表?

Secondly, Is there anything related to a particular user?, if so are you using Database in backend to store the list of orders etc etc..?其次,是否有任何与特定用户相关的内容?如果有,您是否在后端使用数据库来存储订单列表等?

Assuming you are using database for user to store his orders and all, do the following...假设您正在为用户使用数据库来存储他的订单和所有内容,请执行以下操作...

  1. Store user ID in session storage after successful login.登录成功后将用户 ID 存储在session存储中。
  2. Use this session user ID in whatever page you want to query accordingly (eg:- select * from blahblah where userid="$_SESSION['userid']"; )在您要相应查询的任何页面中使用此 session 用户 ID(例如:- select * from blahblah where userid="$_SESSION['userid']";
  3. Retrieve orders, profile etc anything using php and database.使用 php 和数据库检索订单、配置文件等。
  4. Learn to mix-up html and php code and make a dynamic page with php and database query.学习混淆html和php代码,用php和数据库查询制作动态页面。
  5. Use Ajax request to retrieve data from php, or use simple form handling (but page will be less dynamic and you need to refresh page)使用 Ajax 请求从 php 检索数据,或使用简单的表单处理(但页面动态性较低,您需要刷新页面)
  6. After making request to delete an order item, delete it in database that would be enough.在提出删除订单项目的请求后,在数据库中删除它就足够了。

After all these you will get what you want cuz while receiving orders from database you don't get the item which got deleted.毕竟这些你会得到你想要的,因为在从数据库接收订单时你没有得到被删除的项目。

As your code was not sufficient for me I didn't answer with coding example.由于您的代码对我来说还不够,我没有回答编码示例。

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

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