我有一个带有两个链接下拉列表的表单,我需要进行许多克隆,但保留链接。
这是一个示例,链式组合在我的应用程序中带有 json。
链式代码:
<form id="test" action="/ventas/add/" >
<div class="row-fluid">
<div class="row-fluid">
<div class="span5">
<label for="VentaComunicacioneId">Programas:</label>
<select id="VentaProgramaId">
<option value="" selected="selected">(Seleccione Programa)</option>
<?php foreach($programas as $key => $programa): ?>
<option class="<?php echo $key; ?>" value="<?php echo $key; ?>"><?php echo $programa; ?></option>
<?php endforeach; ?>
</select>
</div><!--/span-->
<div class="span6">
<label for="VentaComunicacioneId">Niveles:</label>
<select id="VentaMuestraId" name="data[Muestra][muestra_id]">
</select>
<div style="margin:-36px 0px 10px 223px; position:relative;">
<button class="btn btn-small btn-success" id="add" type="button">+</button><button class="btn btn-small btn-danger" id="remove" type="button">-</button>
</div>
<div id="clon">
</div>
</div><!--/span-->
</div><!--/row-->
</div>
<div class="row-fluid">
<div class="span10">
<label>Comentarios:</label>
<textarea id="comentario" name="data[Venta][comentario]" class="field span12" placeholder="Comentario" rows="5"></textarea>
</div>
</div>
<div class="row-fluid">
<div class="span4">
<button class="btn btn-warning" id="sbmit" type="submit">Guardar</button>
</div>
</div>
</div><!--/row-->
</div><!--/span-->
</div>
<div class="span4">
</div><!--/span-->
<?php echo $this->Form->hidden('colegio_id'); ?>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#VentaProgramaId').on("change",function() {
var id = $(this).val();
var select = $('#VentaMuestraId');
select.empty();
$('<option/>').attr('value', 0).html('- Seleccione Nivel -').appendTo(select);
$.getJSON('/admin/muestras/get/'+id, function(data) {
$.each(data, function(key, val){
$('<option/>').attr('value', val.Muestra.id).html(val.Muestra.nombre).appendTo(select);
});
});
});
$('#add').on("click",function() {
$('#VentaMuestraId').clone().appendTo('#clon');
$('#VentaProgramaId').clone().appendTo('#clon');
});
});
</script>