带有jQuery的动态HTML表
我有一个表,用户可以在其中动态添加行。对于添加的所有行,其中一个字段“我的日期”字段必须相同。我已经在所有其他行上克隆了日期字段,并在创建的行上使该字段为只读,但我想知道是否有一种方法可以在其中添加一些代码,如果用户返回到第一行并更改收据日期,那么用户添加的所有行也将更新为新日期带有jQuery的动态HTML表,jquery,Jquery,我有一个表,用户可以在其中动态添加行。对于添加的所有行,其中一个字段“我的日期”字段必须相同。我已经在所有其他行上克隆了日期字段,并在创建的行上使该字段为只读,但我想知道是否有一种方法可以在其中添加一些代码,如果用户返回到第一行并更改收据日期,那么用户添加的所有行也将更新为新日期 <table border="0" width="825px" cellspacing="0" cellpadding="5" name="receipts" id = "receipts"> <th
<table border="0" width="825px" cellspacing="0" cellpadding="5" name="receipts" id = "receipts">
<thead>
<tr>
<th class="colheader" width="125px">Receipt #</th>
<th class="colheader" width="120px">Date</th>
<th class="colheader" width="120px">Category</th>
<th class="colheader" width="120px">Description</th>
<th class="colheader" width="120px">Amount</th>
<th class="colheader" width="145px"><span class="boldblacklinks"><a href="#" id="add">[Add +]</a></span></th>
</tr>
</thead>
<tbody class="lineBdy">
<tr id="line_1" class="spacer">
<td><input type="text" class="receipt fieldclasssm" id="recLineReceipt[]" name="recLineReceipt[]" size="7" value = "<?=$receiptNumber?>"/></td>
<td><input type="text" class="date fieldclasssm" id="recLineDate[]" name="recLineDate[]" size="10" value = "<?=date("m/d/Y", strtotime($today))?>"/></td>
<td><select name="selectCategory[]" class="fieldclasssm">
<option value = "">Select a Category...</option>
<?php //Get Categories
$getCats = mysql_query("SELECT id, nominalName FROM expense_nominalCodes ORDER BY id") or die("Get Cats: " . mysql_error());
if(mysql_num_rows($getCats) > 0)
{
while($catData = mysql_fetch_array($getCats))
{
echo '<option value = "'.$catData['id'].'">'.$catData['nominalName'] . '</option>';
}
}
?>
</select>
</td>
<td><input type="text" class="lineDescr fieldclasssm" name="recLineDescr[]" id="recLineDescr[]" value = "<?=$_POST['recLineDescr']?>" size="40" /></td>
<td colspan = "2"><input type="text" class="amt fieldclasssm" name="recLineAmount[]" id="recLineAmount[]" value = "<?=$_POST['recLineAmount']?>" size="12" /></td>
</tr>
</tbody>
</table>
<div align="center"><br /><br /><input type="submit" name = "saveAdd" class="btn" value = "Save & Add Another Receipt" /> <input type="submit" name = "saveAdd" class="btn" value = "Save as Draft" /> <input type="submit" class="btn"name="saveDraft" value = "Save & Finalize Expense Report" /><br /><br /></div>
收据#
日期
类别
描述
数量
如果这些字段都有date
类,您可以调用
$('#someUpdateButton').click(function(){
$('.date').val($('.date:nth-of-type(1)').val())
});
只是一个想法,动态添加的行可以包含自定义数据属性(添加的数据)
),如果一行有此属性,并且用户更改了日期,请更新这些行。您有示例代码让我开始吗?我对jQuery太陌生了。一旦选择了新的日期而不必按更新按钮,是否可以这样做?@Dan Yeah你可以使用任何事件处理程序。点击按钮是我打字最快的一次。您希望在键入日期时像这样做吗?我正在使用jQuery日期选择器生成日期。
$('#someUpdateButton').click(function(){
$('.date').val($('.date:nth-of-type(1)').val())
});