简体   繁体   English

克隆具有多个DIV的DIV,这些DIV在使用selected()的模态中包含一个选择

[英]Cloning a DIV with Multiple DIVs that include a select inside a modal that uses chosen()

enter image description here I have a modal which opens a form, the form has a line with 4 fields 在此处输入图片描述,我有一个打开表格的模态,该表格有一行包含4个字段的行

  1. Select input field 选择输入栏
  2. Text 文本
  3. Select input field (filtered by first select) 选择输入字段(按第一次选择过滤)
  4. Select input field (filtered by second select) 选择输入字段(由第二选择过滤)

I want to clone this line with empty values. 我想用空值克隆此行。 I was able to clone it, but in the cloned line, whenever I try to select a new value, it expands the first field in first line only. 我能够克隆它,但是在克隆的行中,每当我尝试选择一个新值时,它只会在第一行中扩展第一个字段。

Modal Code 模态代码

<div id="add-ins-company">
<div class="form-group">
<div class="col-md-4">
<div class="input-group col-md-12">
<select id="mq_ins_company" name="mq_ins_company[]" class="modal-select-chosen" data-placeholder="Insurance Company" onchange="getpolicyclass(this.value);" required>
<option value=""></option>
<?php 
$company_id = mysqli_real_escape_string($GLOBALS['con'], $_SESSION['company_id']);
$sql = "select * from insurance_companies where ins_comp_company = $company_id";
$data = FetchMultipleData($sql);
for($i=0;$i<count($data);$i++) {
?>
<option value="<?php echo $data[$i]['ins_comp_id']; ?>"><?php echo $data[$i]['ins_comp_name'];?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-2">
<input type="email" id="mq_fees" name="mq_fees[]" class="form-control" placeholder="Fees" required="required">
</div>
<div class="col-md-3">
<div id="mq_class"></div>
</div>
<div class="col-md-3">
<div id="mq_size"></div>
</div>
</div>
</div>

JavaScript 的JavaScript

function addcompanyrow() {
  var row = $('#add-ins-company').clone(true);
  $(row).insertAfter("#add-ins-company");
}

Any Suggestion on the following: 关于以下任何建议:

  1. Clear all input values 清除所有输入值
  2. Remove the chosen class and reapply it on the cloned line 删除所选的类,然后将其重新应用于克隆的行

In general: 一般来说:

If the list is dynamic you should have some workaround, such as: 如果列表是动态的,则应该有一些解决方法,例如:

  • Consider move the php generations to external ajax calls hosted in js functions. 考虑将php代移到js函数中托管的外部ajax调用。

  • Use a binding of option of 3rd-parties like JQuery/KnockoutJS. 使用诸如JQuery / KnockoutJS之类的第三方选项的绑定。

Anyway, if i understand your specific question well: 无论如何,如果我能很好地理解您的特定问题:

Clearing input values is possible like this: 清除输入值的方法如下:

$('<the_input_selector>').removeAttr('value');

OR 要么

$('<the_input_selector>').val('');

For clearing "select" elem you can also use: 为了清除“选择”元素,您还可以使用:

$('<the_select_selector>').val('');

if the empty option exists. 如果存在空选项。 OR you can set it to first one: 或者您可以将其设置为第一个:

$('<the_select_selector>').prop('selectedIndex',0);

Removing class is possible too: 也可以删除类:

$('<the_select_selector>').removeClass('modal-select-chosen');

You can then add any other class: 然后,您可以添加任何其他类:

$('<the_select_selector>').addClass('<any_other_class>');

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM