2011-08-13 19 views
1

jqueryを使用して編集ダイアログボックスを作成するにはどうすればよいですか?たとえば、データがいっぱいのhtmlテーブルがあり、行のボタンをクリックすると、その行のデータがjqueryダイアログボックスに表示されます。phpのjqueryダイアログを使用してデータを編集する

データを追加したりデータを削除するダイアログボックスを作成することはできますが、データを編集してjqueryのテキストボックスにデータを入力するには、実際には考えられません。

答えて

1

あなたは、この行のすべてのセルのデータを取得し、ダイアログボックスに渡し、このボタンをクリックするだけで、各列の最後のセルに

<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ボタンがあります。

0

私はテーブルの各行にidを付けるのが簡単だと思います。次に、サーバーからデータを取得できます。

関連する問題