我正在动态创建一个表并想要捕获动态创建日期文本框上的按键事件。如果我只有一个payment_date文本框,那很好,但我有很多。我已经看过.live,但我太新了,以此弄清楚。有人可以为我特定吗?这里是有问题的文本框的HTML:关于动态创建文本框的jQuery按键事件
<?php
foreach($student_classes as $class):
if($student['student_id'] == $class['student_id']) {
$i = $class['registration_id'];
$deleted = FALSE;
?>
<td>
<input type="text"
name="students[<?php echo $i ?>][registration_payment_date]"
id="payment_date[<?php echo $i ?>]"
value="<?= html($class['registration_payment_date']) ?>"
size='10' maxlength="10"
>
</td>
<?php endforeach; ?>
的jQuery:
jQuery(document).ready(function()
{
var $payment_date = jQuery('#payment_date');
// Format the date as it is entered
$payment_date.keypress(function(event) {
DateFormat(this, this.value, event, false, '1');
});
// Check to make sure the date is valid
$payment_date.change(function()
{
if(dateValid(this.value) == false);
alert('The date is not valid');
});
});
谢谢!
谢谢。我过于复杂 - 它使用起来非常简单。我会再读一遍,以便我能理解它。 – Sara