我有一個問題,存儲值的動態創建的按鈕,可以打開對話框。
Dialog是相同的所有按鈕,所以我有這樣的定義:動態創建的對話框的存儲值(ID)
$('<div id="dialog-form" title="Change coordinates">' +
'<p class="validateTips">Both fields are required.</p>' +
'<form>' +
'<fieldset>' +
'<label for="lon">Longitude (decimal)</label>' +
'<input type="text" name="lon" id="lon" value="" class="text ui-widget-content ui-corner-all">' +
'<label for="lat">Latitude (decimal)</label>' +
'<input type="text" name="lat" id="lat" value="" class="text ui-widget-content ui-corner-all">' +
'<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">' +
'</fieldset>' +
'</form>' +
'</div>').appendTo(document.body);
然後我生成與特殊的「創建」按鈕,對話框按鈕:
$("#create").button().on("click", function()
{
var btn1 = document.createElement("BUTTON");
btn1.id = "change_coord";
var t1 = document.createTextNode("Change coordinates");
btn1.appendChild(t1);
document.body.appendChild(btn1);
generator++;
});
然後,我有一個對話框聲明和函數來處理我的對話框輸入,在此之後,我試圖打印輸入和我的id(來自發生器的值)。輸入很酷,但ID不起作用。
例如,我生成3個按鈕,如btn1:1,btn2:2,btn3:3(button:id),但所有按鈕的id輸出均爲3.
我的應用程序將創建動態對象,我想修改此對象通過這個對話框。 「ID」值將被用作我的數據庫的「指針」。所以當我點擊第一個創建的按鈕時,無論我創建了多少個按鈕,它仍然必須具有「ID」值== 1
FIDDLE來模擬我的情況。
謝謝大家的時間和意見。
看起來過於複雜,但並不確定你正在嘗試創建多個對話框都是一樣的。爲什麼不使用一個對話框? – charlietfl
@charlietfl因爲我的應用程序將創建動態對象,我想通過這個對話框修改這個對象。 「ID」值將被用作我的數據庫的「指針」。所以當我點擊第一個創建的按鈕時,無論我創建了多少個按鈕,它都必須具有「ID」值== 1 –