我希望这是我的脚本,而不是 Jquery 错误(版本 1.4.4)。这个脚本在几个表的第一行上运行良好。jquery 或用户输入放置和发布的值是正确的。但是在表格列表的末尾,表单开始错误地提交(用萤火虫检查)。所发生的是为先前条目发布的值,而不是用户输入的实际文本。例如 2012-10-4 的表格工作正常,但 2012-09-13 的表格不正确:
jQuery:
(function ($) {
Drupal.behaviors.mvc = {
attach: function(context, settings) {
$(document).ready(function() {
// container start
$('#timetracker-mytime-').ajaxForm({
success: function(result){
var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var output = d.getFullYear() + '-' +
((''+month).length<2 ? '0' : '') + month + '-' +
((''+day).length<2 ? '0' : '') + day;
var section = result.split('}{');
// show any previously hidden tables
//$('#table-').show();
$("div:hidden[id*='table-']").show();
// hide the working table
// $('#table-' + section[0]).hide();
$('div#most-recent-events table > tbody').prepend(section[1]);
// remove the last row to keep the list short ( 5 rows )
$('div#most-recent-events table > tbody > tr:last').remove();
$('div#table-' + section[0] + ' table > thead').append(section[1]);
// show new working table
/*$('#output').html(section[1]).css({
backgroundColor: '#99FF66',
padding: '10px'
});*/
;
}
});
$('#timetracker-myreports-').ajaxForm({
target:'#output',
success: function(){
$('#export-form').show();
$("#my-report-id").val($('#edit-my-projects-id option:selected').val());
}
});
$('#update-mini-form').ajaxForm({
target: this});
$( "#edit-event-date" ).AnyTime_picker(
{ format: "%Y-%m-%d",
formatUtcOffset: "%: (%@)",
placement: "popup" });
$("a.delete-time").live("click", function(event) {
event.preventDefault();
var row = $(this).attr("id").split('-');
var delurl = $(this).attr("href");
$.ajax({
type: "GET",
url: delurl,
dataType: "html",
cache: false,
success: function(result){
$("#row-" + row[1]).remove();
$('#total-user-hours').html(result);
}
});
return false;
});
$("a.update-time").live("click", function(event) {
event.preventDefault();
var row = $(this).attr("id").split('-');
$("tr:visible[class*='temp-form']").hide();
$('#row-' + row[1]).after(
$("#mini-form-row").addClass('temp-form').show('slow')
);
$("#update-entry").show();
// fill in form values
$("#update-entry #id-mini-form").val($("tr#row-" + row[1] + " td.cell-1-" + row[1]).text());
$("#update-entry #edit-task").val($("tr#row-" + row[1] + " td.cell-2-" + row[1]).text());
$("#update-entry #edit-hours").val($("tr#row-" + row[1] + " td.cell-5-" + row[1]).text());
$("#projects option[value=" + $('#row-' + row[1] + ' > td > #my-projects-id').val() +"]").attr("selected","selected");
});
$("div.form-close").live("click", function(event) {
$("tr:visible[id*='mini-form-']").hide();
});
$("#sendUpdate").live("click",function() {
$.ajax({
type: "POST",
url: "http://drupal.se/timetracker/timetracker/update_time/",
data: $('#update-entry').serialize(),
cache: false,
success: function(result){
section = result.split('}{');
$('#row-' + section[0]).replaceWith(section[1]);
}
});
return false;
});
$('#edit-export').live("click", function(){
$('#timetracker-myreports-csv-').attr("action", 'http://drupal.se/timetracker/timetracker/myreport_csv/');
$('#timetracker-myreports-csv-').submit();
});
// container end
});
}
};
})(jQuery);
<div id="table-2012-10-03"><div class="table-label"><span class="date">2012-10-03</span><span class="hours"></span></div><table class="sticky-enabled">
<thead><tr><th>ID</th><th>Task</th><th>Project</th><th></th><th>Hours</th><th colspan="2">Operations</th> </tr></thead>
<tbody>
<tr id="row-213" class="odd"><td class="cell-1-213">213</td><td class="cell-2-213">the last try before</td><td class="cell-3-213">how beans</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="204"></td><td class="cell-5-213">2</td><td class="cell-6-213"><a href="/timetracker/timetracker/delete_time/213/204" class="delete-time" id="del-213">delete</a></td><td class="cell-7-213"><a href="/timetracker/timetracker/update_time/213" class="update-time" id="upd-213">update</a></td> </tr>
<tr id="row-212" class="even"><td class="cell-1-212">212</td><td class="cell-2-212">dd more because our english has gotten terrible</td><td class="cell-3-212">how beans</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="204"></td><td class="cell-5-212">2</td><td class="cell-6-212"><a href="/timetracker/timetracker/delete_time/212/204" class="delete-time" id="del-212">delete</a></td><td class="cell-7-212"><a href="/timetracker/timetracker/update_time/212" class="update-time" id="upd-212">update</a></td> </tr>
<tr id="row-211" class="odd"><td class="cell-1-211">211</td><td class="cell-2-211">discovering clean fuel sources</td><td class="cell-3-211">how beans</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="204"></td><td class="cell-5-211">2</td><td class="cell-6-211"><a href="/timetracker/timetracker/delete_time/211/204" class="delete-time" id="del-211">delete</a></td><td class="cell-7-211"><a href="/timetracker/timetracker/update_time/211" class="update-time" id="upd-211">update</a></td> </tr>
<tr id="row-209" class="even"><td class="cell-1-209">209</td><td class="cell-2-209">riding the rainbow</td><td class="cell-3-209">project nine</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="196"></td><td class="cell-5-209">2</td><td class="cell-6-209"><a href="/timetracker/timetracker/delete_time/209/196" class="delete-time" id="del-209">delete</a></td><td class="cell-7-209"><a href="/timetracker/timetracker/update_time/209" class="update-time" id="upd-209">update</a></td> </tr>
<tr id="row-206" class="odd"><td class="cell-1-206">206</td><td class="cell-2-206">a game of bones</td><td class="cell-3-206">project ten</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="197"></td><td class="cell-5-206">2</td><td class="cell-6-206"><a href="/timetracker/timetracker/delete_time/206/197" class="delete-time" id="del-206">delete</a></td><td class="cell-7-206"><a href="/timetracker/timetracker/update_time/206" class="update-time" id="upd-206">update</a></td> </tr>
<tr id="row-205" class="even"><td class="cell-1-205">205</td><td class="cell-2-205">a game of thrones</td><td class="cell-3-205">project ten</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="197"></td><td class="cell-5-205">2</td><td class="cell-6-205"><a href="/timetracker/timetracker/delete_time/205/197" class="delete-time" id="del-205">delete</a></td><td class="cell-7-205"><a href="/timetracker/timetracker/update_time/205" class="update-time" id="upd-205">update</a></td> </tr>
<tr id="row-203" class="odd"><td class="cell-1-203">203</td><td class="cell-2-203">trial and lots of errors</td><td class="cell-3-203">project two</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="181"></td><td class="cell-5-203">4</td><td class="cell-6-203"><a href="/timetracker/timetracker/delete_time/203/181" class="delete-time" id="del-203">delete</a></td><td class="cell-7-203"><a href="/timetracker/timetracker/update_time/203" class="update-time" id="upd-203">update</a></td> </tr>
<tr id="row-192" class="even"><td class="cell-1-192">192</td><td class="cell-2-192">driving to philly to get cream cheese</td><td class="cell-3-192">project three to one</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="182"></td><td class="cell-5-192">1</td><td class="cell-6-192"><a href="/timetracker/timetracker/delete_time/192/182" class="delete-time" id="del-192">delete</a></td><td class="cell-7-192"><a href="/timetracker/timetracker/update_time/192" class="update-time" id="upd-192">update</a></td> </tr>
<tr class="odd"><td></td><td></td><td></td><td>Total Hours:</td><td colspan="3" id="total-user-hours">17</td> </tr>
<tr id="mini-form-row" style="display:none" class="even"><td colspan="7"><div style="text-align:right;cursor:pointer;" class="form-close">close x</div><form method="post" style="display:none" id="update-entry" action="http://drupal.se/timetracker/timetracker/update_time"><table><tr><td><label>Task<input type="textfield" id="edit-task" name="task" value="" size="12"></label></td><td><label>Projects<select id="projects" name="projects"><option selected="selected" value="none"></option><option value="204">how beans</option><option value="217">New project</option><option value="199">project 12</option><option value="206">project 14</option><option value="195">project eight</option><option value="202">project eleven</option><option value="203">project eleven</option><option value="205">project eleven</option><option value="187">project five and five</option><option value="186">project four and seven</option><option value="196">project nine</option><option value="180">project one</option><option value="209">project one</option><option value="210">project one</option><option value="211">project one</option><option value="212">project one</option><option value="213">project one</option><option value="214">Project One</option><option value="215">Project One</option><option value="193">project six</option><option value="197">project ten</option><option value="182">project three to one</option><option value="181">project two</option></select></label></td><td><input type="hidden" name="id_mini_form" id="id-mini-form" value="place"></td><td><label>Hours<input type="textfield" id="edit-hours" name="hours" size="2" value=""></label><td><input type="button" id="sendUpdate" value="update"></td></tr></table></form></td> </tr>
</tbody>
</table>
</div>
<div id="table-2012-09-19"><div class="table-label"><span class="date">2012-09-19</span><span class="hours"></span></div><table class="sticky-enabled">
<thead><tr><th>ID</th><th>Task</th><th>Project</th><th></th><th>Hours</th><th colspan="2">Operations</th> </tr></thead>
<tbody>
<tr id="row-214" class="odd"><td class="cell-1-214">214</td><td class="cell-2-214">hullo world</td><td class="cell-3-214">project nine</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="196"></td><td class="cell-5-214">4</td><td class="cell-6-214"><a href="/timetracker/timetracker/delete_time/214/196" class="delete-time" id="del-214">delete</a></td><td class="cell-7-214"><a href="/timetracker/timetracker/update_time/214" class="update-time" id="upd-214">update</a></td> </tr>
<tr class="even"><td></td><td></td><td></td><td>Total Hours:</td><td colspan="3" id="total-user-hours">4</td> </tr>
<tr id="mini-form-row" style="display:none" class="odd"><td colspan="7"><div style="text-align:right;cursor:pointer;" class="form-close">close x</div><form method="post" style="display:none" id="update-entry" action="http://drupal.se/timetracker/timetracker/update_time"><table><tr><td><label>Task<input type="textfield" id="edit-task" name="task" value="" size="12"></label></td><td><label>Projects<select id="projects" name="projects"><option selected="selected" value="none"></option><option value="204">how beans</option><option value="217">New project</option><option value="199">project 12</option><option value="206">project 14</option><option value="195">project eight</option><option value="202">project eleven</option><option value="203">project eleven</option><option value="205">project eleven</option><option value="187">project five and five</option><option value="186">project four and seven</option><option value="196">project nine</option><option value="180">project one</option><option value="209">project one</option><option value="210">project one</option><option value="211">project one</option><option value="212">project one</option><option value="213">project one</option><option value="214">Project One</option><option value="215">Project One</option><option value="193">project six</option><option value="197">project ten</option><option value="182">project three to one</option><option value="181">project two</option></select></label></td><td><input type="hidden" name="id_mini_form" id="id-mini-form" value="place"></td><td><label>Hours<input type="textfield" id="edit-hours" name="hours" size="2" value=""></label><td><input type="button" id="sendUpdate" value="update"></td></tr></table></form></td> </tr>
</tbody>
</table>
</div><div id="table-2012-09-13"><div class="table-label"><span class="date">2012-09-13</span><span class="hours"></span></div><table class="sticky-enabled">
<thead><tr><th>ID</th><th>Task</th><th>Project</th><th></th><th>Hours</th><th colspan="2">Operations</th> </tr></thead>
<tbody>
<tr id="row-215" class="odd"><td class="cell-1-215">215</td><td class="cell-2-215">hullo world two</td><td class="cell-3-215">project one</td><td><input type="hidden" name="my_projects_id" id="my-projects-id" value="180"></td><td class="cell-5-215">4</td><td class="cell-6-215"><a href="/timetracker/timetracker/delete_time/215/180" class="delete-time" id="del-215">delete</a></td><td class="cell-7-215"><a href="/timetracker/timetracker/update_time/215" class="update-time" id="upd-215">update</a></td> </tr>
<tr class="even"><td></td><td></td><td></td><td>Total Hours:</td><td colspan="3" id="total-user-hours">4</td> </tr>
<tr id="mini-form-row" style="display:none" class="odd"><td colspan="7"><div style="text-align:right;cursor:pointer;" class="form-close">close x</div><form method="post" style="display:none" id="update-entry" action="http://drupal.se/timetracker/timetracker/update_time"><table><tr><td><label>Task<input type="textfield" id="edit-task" name="task" value="" size="12"></label></td><td><label>Projects<select id="projects" name="projects"><option selected="selected" value="none"></option><option value="204">how beans</option><option value="217">New project</option><option value="199">project 12</option><option value="206">project 14</option><option value="195">project eight</option><option value="202">project eleven</option><option value="203">project eleven</option><option value="205">project eleven</option><option value="187">project five and five</option><option value="186">project four and seven</option><option value="196">project nine</option><option value="180">project one</option><option value="209">project one</option><option value="210">project one</option><option value="211">project one</option><option value="212">project one</option><option value="213">project one</option><option value="214">Project One</option><option value="215">Project One</option><option value="193">project six</option><option value="197">project ten</option><option value="182">project three to one</option><option value="181">project two</option></select></label></td><td><input type="hidden" name="id_mini_form" id="id-mini-form" value="place"></td><td><label>Hours<input type="textfield" id="edit-hours" name="hours" size="2" value=""></label><td><input type="button" id="sendUpdate" value="update"></td></tr></table></form></td> </tr>
</tbody>
</table>
</div>