2
好吧,让我们说,我有div内的表单元素。我希望能够通过使用jQuery单击按钮来克隆该div,并添加表单的版本2,因此所有元素ID都将在其名称中加1。Clone div和增量重命名元素ID
<div id="card">
<!-- PART 1 -->
<h1 class="card_build">Build your card options:</h1>
<select id="country" name="country[]">
<?php
include('lib/class_dbcon.php');
$connect = new doConnect();
$q = mysql_query("SELECT * FROM country ORDER BY country_id ASC");
while($row = mysql_fetch_assoc($q))
{
echo '<option value="'.$row['country_id'].'">'.$row['country_option'].'</option>';
}
?>
</select>
<select id="filter" name="filter[]">
<option value="">-- Select Filter --</option>
</select>
<select id="load_choice" name="load_choice[]">
<option value="">-- Select Load_choice --</option>
</select>
<select id="plastic" name="plastic[]">
<option value="">-- Select Plastic --</option>
</select>
<select id="UG_tipping" name="UG_tipping[]">
<option value="">-- Select UG/Tipping --</option>
</select>
<!-- PART 1 -->
<!-- PART 2 -->
<div id="part2" style="margin-top:10px;">
<h1 class="card_build">Customize the card:</h1>
<input type="text" name="3rdLine" size="32" class="field" id="3rdLine">
<input type="text" name="4thLine" size="32" class="field" id="4thLine">
<input type="text" name="card_value" size="32" class="field" id="card_value">
<label for="showpoints">Show "Points"?</label>
<input type="checkbox" value="points" class="checkbox" checked="checked">
<label for="cobrand">Co-branded?</label>
<input type="checkbox" value="cobrand" class="checkbox" checked="checked">
<textarea rows="5" name="message" class="textarea" id="message"></textarea>
<hr>
</div>
<!-- PART 2 -->
</div>
<a href="#" onCLick="moreFields()">ADD</a>
所以,如果你看一下这个代码和你点击添加链接它会重复结束,把它变成做同样的事情,所有的div里面的元素ID为好。作品中的一个问题是我需要5个克隆的MAXIMUM,所以脚本只能增加4倍(或者5无关紧要,只要我能看到创建最大值的方法)。
我唯一的问题是,当克隆div时,PHP注入是否会保持机智?在此先感谢,我一直在这整个夜晚都在绞尽脑汁。
这将既创建表格元素的一个新组,并且还连接与它们相关联的事件。 – burntblark 2010-10-24 15:38:40