javascript - 通过 mysqli-php 选择在 javascript 中克隆
问题描述
我正在开发这个选择,我可以在其中使用 javascript 进行克隆。
但在此之前,我有这个脚本来选择选项。
<script type="text/javascript">
$(document).ready(function () {
$('select').on('change', function (e) {
var selected_value = $(this).val();
var option_data = $(this).children('option[value="' + selected_value + '"]');
// get data values
var visanumber = option_data.data('visanumber');
var idnumber = option_data.data('idnumber');
var tesdaNumber = option_data.data('tesdanumber');
var subdate = option_data.data('subdate');
// the photo
var accntVisaPhotoPath = option_data.data('accntvisaphotopath');
$(this).closest('td').siblings().find('img.accntVisaPhotoPath').attr('src', accntVisaPhotoPath);
var passportPath = option_data.data('passportpath');
$(this).closest('td').siblings().find('img.passportPath').attr('src', passportPath);
// set the values
$(this).closest('td').siblings().find('span.visanumber').text(visanumber);
$(this).closest('td').siblings().find('span.idnumber').text(idnumber);
$(this).closest('td').siblings().find('span.tesdaNumber').text(tesdaNumber);
$(this).closest('td').siblings().find('span.subdate').text(subdate);
});
});
</script>
上面的脚本运行良好,我决定使用另一个 javascript 来克隆 SELECT,以便最多使用 10 个 SELECT。没有它,添加 10 个 SELECT 就太崩溃了。
<script type="text/javascript">
var regex = /^(.+?)(\d+)$/i;
var cloneIndex = $(".clonedInput").length;
function clone(){
$(this).parents(".clonedInput").clone()
.appendTo("body")
.attr("id", "clonedInput" + cloneIndex)
.find("*")
.each(function() {
var id = this.id || "";
var match = id.match(regex) || [];
if (match.length == 3) {
this.id = match[1] + (cloneIndex);
}
})
.on('click', 'button.clone', clone)
.on('click', 'button.remove', remove);
cloneIndex++;
}
function remove(){
$(this).parents(".clonedInput").remove();
}
$("button.clone").on("click", clone);
$("button.remove").on("click", remove);
</script>
顺便说一句,第二个脚本在此脚本中调用后无法运行。
<?php
$result = mysqli_query($db, "SELECT * FROM applicant WHERE masterStat='CVF-Active' AND (tesdaNumber !='') AND (passport !='') ORDER BY appID");
?>
<div align="center">
<form name="listUsers" method="post" action="cvsEmail.php" enctype="multipart/form-data" accept-charset="UTF-8">
<table border="1px" width="600">
<tr>
<th>
<div align="center"> Applicant Name </div>
</th>
<th>
<div align="center"><font color="red"> TESDA Number </font></div>
</th>
<th>
<div align="center"> Passport </div>
</th>
</tr>
<tr align="center" bgcolor="red">
<td colspan="3">
Email:
<select name="email">
<option value="">Select FIRST</option>
<option value="xxx@live.com.ph">Test</option>
<option value="xxxs@hotmail.com">Al XXXX</option>
<option value="ssgfgf@gmail.com">Al XXXXXX</option>
</select>
</td>
</tr>
<tr>
<td>
<div id="clonedInput1" class="clonedInput">
<div>
<label for="users" class="">Applicant: <span class="requiredField">*</span></label>
<select class="" name="users[]" id="users">
<?php
echo "<option value=\"\">Select:</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['appID'] . "' data-tesdaNumber='" . $row['tesdaNumber'] . "' data-passportPath='http://emmanuelstaffing.com/webV2/acf/" . $row['passportPath'] . "'>" . $row['fName'] . " " . $row['lName'] . "</option>";
}
//First var
$_REQUEST['appID'];
?>
</select>
<div class="actions">
<button class="clone">Add One</button>
<button class="remove">Remove</button>
</div>
</div>
</div>
有什么建议克隆它吗?
解决方案
推荐阅读
- ajax - 将 AJAX 分页添加到自定义帖子类型
- hybris - 如何在hybris.中创建订单级促销?
- javascript - 在 styled-components 中传递 window.onload 的函数
- swift - iphoneX 不调用 prefersStatusBarHidden
- ios - 应用商店应用的 Stripe 支付网关
- php - 一些图片无法在 html 中显示
- jquery - 侧栏打开时隐藏和页脚jquery
- python - 通过pandas python写入csv文件中的连续行
- jenkins - 需要自动化构建过程以进行部署
- python - 计算时间序列中值超过阈值的次数