每次点击添加更多学生
链接时,我都会克隆整个 div。
克隆可以工作,但无法从克隆 div 的克隆选择框中选择选项。
HTML
<div id="all">
<div id="student" class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">Firstname</label>
<label style="color:red;" id="std_first_name_error"></label>
<div class="append-icon">
<input type="text" id="std_first_name" name="std_first_name1" id="password" class="form-control" placeholder="Enter first name" minlength="4" maxlength="16" required>
<i class="icon-lock"></i>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">Select School</label>
<label style="color:red;" id="std_scl_error"></label>
<div class="option-group">
<select name="std_scl_name1" class="language" required>
<option value="">Select school..</option>
<?php foreach ($schools as $school) :?>
<option value="<?php echo $school->sch_id; ?>"><?php echo $school->sch_name;?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
</div>
</div>
<div id="add_student"><a><u>Add More Students</u></a></div>
脚本
<script type="text/javascript">
$(document).ready(function(){
var count = 2;
$('#add_student').click (function(e){
e.preventDefault();
var clonedEl = $('#student').first().clone();
clonedEl.find(':text').attr('name','std_first_name'+count);
//Add the newly div the the entire div
$('#all').append(clonedEl);
//$('[name="std_scl_name'+count+'"]').html($('[name="std_scl_name1"]').html());
});
});
</script>
申请
最佳答案
您的相同代码在 this fiddle 中运行良好。我更改/添加的是唯一的<option>
元素。我仍然可以从克隆的 div 的 <select>
中选择一个元素.
我认为你需要检查的是 php
片段及其输出。它可能无法满足 <option>
元素。
关于javascript - 克隆后无法从选择框中选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30413085/