簡體   English   中英

使用 php 上的 jquery 對話框編輯數據

[英]Edit data using a jquery dialog on php

如何使用 jquery 創建編輯對話框? 假設我有一個充滿數據的 html 表,如果我單擊一行上的按鈕,它將將該行上的數據顯示到 jquery 對話框中。

我能夠創建一個對話框來添加數據和刪除數據,但要編輯數據並填充 jquery 上的文本框,我真的不知道。

您可以在每行的最后一個單元格中有一個編輯按鈕

<input type="button" calss="edit" value="Edit" />

單擊此按鈕獲取該行的所有單元格數據並將其傳遞給對話框。

$("input.each").click(function(){

  var tr = $(this).closes("tr");
  var data = [];
  tr.find("td:not(:last)").each(function(){
     data.push($(this).text());
  });

  //Here open the dialog box which will have the required fields and using the above data array populate the data fields as required

  //Lets say the first column in the table is for "Name"
  //You can populate the input "Name" field in the dialog box as.
  $("input[name=Name]").val(data[0]);

  //Similarly populate all the data fields using data array

});

該對話框還將有一個Save按鈕,單擊該按鈕將使用已編輯的數據更新當前行的單元格。

我認為您應該在表格的每一行上都有一個 id 以便於識別它。 然后,您可以從服務器獲取數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM