У меня есть файл add_person.ctp, и там у меня есть Входы и функция, но эта функция не работает, Мой вопрос в том, почему она не работает, я не вижу в этом коде ошибки. Если я нажму кнопку, то это ничего не сделает.function add new input
Вот мой код
<h2>People</h2>
<table id="mytable">
<tr><th></th><th>Last Name</th><th>First Name</th><th>Email</th><th>Gender</th></tr>
<tr id="person0" style="display:none;">
<td><?php echo $this->Form->button(' - ',array('type'=>'button','title'=>'Click Here to remove this person')); ?></td>
<td><?php echo $this->Form->input('unused.lastName',array('label'=>'','type'=>'text')); ?></td>
<td><?php echo $this->Form->input('unused.firstName',array('label'=>'','type'=>'text')); ?></td>
<td><?php echo $this->Form->input('unused.email',array('label'=>'','type'=>'text')); ?></td>
<td><?php echo $this->Form->input('unused.gender',array('label'=>'','type'=>'select','options'=>array('M'=>'M','F'=>'F','T'=>'T'))); ?></td>
</tr>
<tr id="trAdd"><td> <?php echo $this->Form->button('+',array('type'=>'button','title'=>'Click Here to add another person','onclick'=>'addPerson()')); ?> </td><td></td><td></td><td></td><td></td></tr>
</table>
<?php echo $this->Html->script(array('jquery-2.1.1.min.js'));?>
<script type='text/javascript'>
var lastRow=0;
function addPerson() {
lastRow++;
$("#mytable tbody>tr:#person0").clone(true).attr('id','person'+lastRow).removeAttr('style').insertBefore("#mytable tbody>tr:#trAdd");
$("#person"+lastRow+" button").attr('onclick','removePerson('+lastRow+')');
$("#person"+lastRow+" input:first").attr('name','data[Person]['+lastRow+'][lastName]').attr('id','personLastName'+lastRow);
$("#person"+lastRow+" input:eq(1)").attr('name','data[Person]['+lastRow+'][firstName]').attr('id','personFirstName'+lastRow);
$("#person"+lastRow+" input:eq(2)").attr('name','data[Person]['+lastRow+'][email]').attr('id','personEmail'+lastRow);
$("#person"+lastRow+" select").attr('name','data[Person]['+lastRow+'][gender]').attr('id','personGender'+lastRow);
}
function removePerson(x) {
$("#person"+x).remove();
}
</script>
Благодарим Вас за помощь!
lol nice! Спасибо за помощь, теперь его работа! :) – Erki
Конечно, проблем нет. Вы можете отметить ответ как принятый :) – Zudwa
Нет проблем! ;) – Erki