【发布时间】:2011-07-22 03:46:27
【问题描述】:
我也有类似的问题。我能够克隆该行并且日期选择器适用于焦点事件,但该按钮始终指向克隆的初始行。我已经尝试过“.removeClass('hasDatepicker')”,这就是完全可以克隆日期选择器的原因。有谁知道为什么按钮仍然不起作用?
这是我的代码:
$(document).ready(function () {
$(function () {
$('#addNew').click(function () {
var tbody = $('#entries tbody');
var rows = tbody.find('tr').length;
var newRow = tbody.find('tr:first').clone(true).appendTo(tbody);
newRow.find(':input').val('').each(function () {
var id = this.id
if (id) {
this.id = this.id.split('_')[0] + '_' + rows;
}
}).end().find('.datepicker').removeClass('hasDatepicker').datepicker();
});
$('.datepicker').datepicker({
autoSize: true,
changeMonth: true,
changeYear: true,
gotoCurrent: true,
showOn: 'both',
buttonImage: '@Url.Content("~/Content/calendar.png")',
buttonText: 'Choose Treatment Date',
NextText: 'Next',
prevText: 'Previous',
showButtonPanel: true
});
});
});
<fieldset>
<h4>Procedures</h4>
<table id="entries" border="1">
<tbody>
<tr>
<td>
Date of Service
<br />
<input type="text" id="DateOfService" class="datepicker" />
</td>
<td>
Procedure Code
<br />
<input type="text" id="ProcedureCode" />
<br />
<a href="#" id="procedureLookup">Lookup</a>
</td>
<td>
Description
<br />
<input type="text" id="ProcedureCodeDescription" />
</td>
<td>
<div id="hasToothAndSurface">
Tooth
<br />
<input type="text" id="Tooth" />
<br />
Surface
<br />
<input type="text" id="Surface"/>
</div>
<div id="NoToothSurface" style="display:none">
<label for="txtNoToothSurface">Tooth/Surface</label>
N/A
</div>
<br />
<a href="#" id="toothSurfaceLookup">Lookup</a>
</td>
<td>
Fee $
<br />
<input type="text" id="ProcedureFee" />
</td>
<td><button type="button" id="deleteRow" class="remove">Remove</button></td>
</tr>
</tbody>
</table>
<button type="button" id="addNew">Add Procedure</button>
</fieldset>
我愿意接受任何建议。我需要用户能够添加 n 多条记录,然后将它们发布到我的 asp.net 控制器,以便我可以处理它们。我正在考虑将输入的名称更改为:
<input type="text" name="in_dateofService[]" />
<input type="text" name="in_code[]" class="my_date" />
<input type="text" name="in_tooth[]" />
<input type="text" name="in_surface[]" />
<input type="text" name="in_fee[]" />
看起来我可以在帖子中将它们作为数组处理。对吗?
【问题讨论】:
-
如果我的回答解决了您的问题,请将其标记为已接受。谢谢。
标签: jquery html html-table datepicker