yii怎么用ajax动态的增加或删除表单元素 [ 新手入门 ]
yii怎么动态的增加或删除表单元素,就是用ajax动态的增加或删除一个文本框,或单选按钮什么的。。。
共 3 条回复
-
我上次做的添加多条工作记录,三段代码放在三个文件里。
效果:
[attach]756[/attach][code]<table> <tr> <th><?php echo WorkExperience::model()->getAttributeLabel('start_date')?></th> <th><?php echo WorkExperience::model()->getAttributeLabel('end_date')?></th> <th><?php echo WorkExperience::model()->getAttributeLabel('organization_name')?></th> <th><?php echo WorkExperience::model()->getAttributeLabel('job_title')?></th> <th><?php echo $batchStudents->status?"":CHtml::link(t('Add'), 'javascript:void(0);', array('onClick'=>'addWorkExperience($(this))', 'class'=>'add'));?></th> </tr> <?php foreach($workExperienceManager->items as $id=>$workExperience){ $this->renderPartial('workExperienceform', array('id'=>$id,'model'=>$workExperience, 'form'=>$form)); } ?> </table> <?php $this->renderPartial('workExperienceJs', array('workExperiences'=>$workExperienceManager, 'form'=>$form));?>
<script type="text/javascript"> var lastWorkExperience=<?php echo $workExperiences->lastNew?>; var trWorkExperience=new String(<?php echo CJSON::encode($this->renderPartial('workExperienceform', array('id'=>'idRep', 'model'=>new WorkExperience, 'form'=>$form), true));?>); function addWorkExperience(button) { lastWorkExperience++; button.parents('table').children('tbody').append(trWorkExperience.replace(/idRep/g,'n'+lastWorkExperience)); } function deleteWorkExperience(button) { button.parents('tr').detach(); } </script>
<tr> <td> <?php echo $form->textField($model,"[$id]start_date",array('style'=>'width:100px','class'=>'hashDatepicker', 'onClick'=>"$('.hashDatepicker').datepicker({ dateFormat: 'yy-mm-dd', changeYear: true });")); ?> <?php echo $form->error($model,"start_date"); ?> </td> <td> <?php echo $form->textField($model,"[$id]end_date",array('style'=>'width:100px','class'=>'hashDatepicker' , 'onclick'=>"$('.hashDatepicker').datepicker({ dateFormat: 'yy-mm-dd', changeYear: true });")); ?> <?php echo $form->error($model,"[$id]end_date"); ?> </td> <td> <?php echo $form->textField($model,"[$id]organization_name",array('size'=>20)); ?> <?php echo $form->error($model,"organization_name"); ?> </td> <td> <?php echo $form->textField($model,"[$id]job_title",array('size'=>20)); ?> <?php echo $form->error($model,"job_title"); ?> </td> <td> <?php echo CHtml::link( t('Delete'), 'javascript:void(0);', array( 'class'=>'delete', 'onClick'=>'deleteWorkExperience($(this))', ));?> </td> </tr>
lkle 南京
注册时间:2012-05-25
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱100
- 威望0
- 积分100