ここで私がしようとしていることがあります。私は、divで書かれたコードのブロックを取得しようとしているdiv/idのいくつかの異なる名前に変更し、フォームに一意の名前で送信することができます。これを行う方法に関するアイデア? 今私のアイデアは、最初に変数をdivに設定してコピーしていて、その中の他のdivにアクセスしますが、それはうまくいかないようです。何か案は?別のID内のIDにアクセスするjquery
var i = 0;
$("#custom_rates").click(function()
{
var sublet_dates_seen = $("#sublet_dates_seen").clone();
// all id's below are within #sublet_dates_seen
sublet_dates_seen.getElementById('#CustomPricePerNightPrice').attr('name','data[CustomPricePerNight][price][' + i ']');
sublet_dates_seen.getElementById(('#CustomPricePerNightStartDateMonth').attr('name','data[CustomPricePerNight][start_date][month][' + i ']');
sublet_dates_seen.getElementById(('#CustomPricePerNightStartDateDay').attr('name','data[CustomPricePerNight][start_date][day][' + i ']');
sublet_dates_seen.getElementById(('#CustomPricePerNightStartDateYear').attr('name','data[CustomPricePerNight][start_date][year][' + i ']');
sublet_dates_seen.getElementById(('#CustomPricePerNightEndDateMonth').attr('name','data[CustomPricePerNight][end_date][month][' + i ']');
sublet_dates_seen.getElementById(('#CustomPricePerNightEndDateDay').attr('name','data[CustomPricePerNight][end_date][day][' + i ']');
sublet_dates_seen.getElementById(('#CustomPricePerNightEndDateYear').attr('name','data[CustomPricePerNight][end_date][year][' + i ']');
sublet_dates_seen.getElementById(('#CustomPricePerNightMinimumNights').attr('name','data[CustomPricePerNight][minimum_nights][' + i ']');
sublet_dates_seen.getElementById(('#CustomPricePerNightMaximumNights').attr('name','data[CustomPricePerNight][maximum_nights][' + i ']');
sublet_dates_seen.appendTo(".avi_specialrates");
i = i + 1;
return false;
});
'g etElementById'はjQuery関数でも、 'document'以外のどこにも定義されていません。参照:https://developer.mozilla.org/en/DOM/document.getElementById – Zirak
IDは一意でなければならないため、要素内の特定のIDを検索するのは意味がありません。 '$( '#CustomPricePerNightPrice')。attr(...)'はうまくいくはずです。同じIDを持つ要素が複数ある場合は、何か問題があります。 –