我用php动态生成这个下拉列表,我用jquery和.text()获取值在另一个id中 我的代码:
<td><select name="maat[<?php echo $key?>]" id="mate<?php echo $key?>">
<?php if ($prod->type==='overige') {?>
<option value="5xl">5xl</option>
<option value="4xl">4xl</option>
<option value="3xl">3xl</option>
<option value="2xl">2xl</option>
<option value="xl">xl</option>
<option value="l">l</option>
<option value="m" selected="selected">m</option>
<option value="s">s</option>
<option value="xs">xs</option>
<option value="2xs">2xs</option>
<option value="3xs">3xs</option>
<option value="4xs">4xs</option>
<option value="5xs">5xs</option>
<?php } else {?>
<option value="30-33">38-40</option>
<option value="34-35">41-43</option>
<option value="39-42" selected="selected">44-46</option>
<option value="43-45">47-49</option>
<?php } ?>
</select></td>
<td ><input type="number" min="0" name="aantal[<?php echo $key?>]" id="aantal<?php echo $key?>" placeholder="0" class="inputQuant text-center" ></td>
<td class=" text-center celll" id="prijsMaat<?php echo $key?>"><?php echo $prod->price ?></td>
我的jquery代码:
<script type="text/javascript">
$(document).ready(function() {
$("#controle2").click(function () {
$("#aantal<?php echo $key?>").each(function (index) {
console.log( index + ": " + $( this ).text() );
let a = $(this).val();
console.log(a);
let num3 =<?php echo $prod->price ?>;
console.log(a*num3);
$("#aantalOverige<?php echo $key?>").text(a);
$("#totaaloverige<?php echo $key?>").text(a*num3);
});
$("#mate<?php echo $key?>").each(function () {
let b = $(this).val();
console.log(b);
$("#waardeOverige<?php echo $key?>").text(b);
console.log($("#waardeOverige<?php echo $key?>"));
});
});
});
//
</script>
在我的实时服务器上,我可以看到myconsole日志的结果,但不能查看.text() printscreen of output