gpt4 book ai didi

javascript - 表单中的多选选项

转载 作者:行者123 更新时间:2023-11-28 05:17:10 24 4
gpt4 key购买 nike

我有一个问题。我需要在一行或多行上重复一个选择选项。像这样的事情:

enter image description here

对于我指定的输入字段

   <td class="col-md-12"><input  name="featureValue[]" value=""></td>
<td class="col-md-12"><input name="featureValue[]" value=""></td>
<td class="col-md-12"><input name="featureValue[]" value=""></td>
<td class="col-md-12"><input name="featureValue[]" value=""></td>

选择我使用的选项

   <select name="listFeature[]" id="listFeature_1">
<option value="1" id="listFeature-0">Material Case </option>
<option value="2" id="listFeature-1">Thickness Case </option>
<option value="3" id="listFeature-2">Color Case</option>
<option value="4" id="featureList-4">Weight</option>
<option value="6" id="featureList-6">Models</option>
<option value="7" id="listFeature-7">Type Movement</option>
</select>
<select name="listFeature[]" id="listFeature_2" >
<option value="1" id="listFeature-0">Material Case </option>
<option value="2" id="listFeature-1">Thickness Case </option>
<option value="3" id="listFeature-2">Color Case</option>
<option value="4" id="featureList-4">Weight</option>
<option value="6" id="featureList-6">Models</option>
<option value="7" id="listFeature-7">Type Movement</option>
</select>
<select name="listFeature[]" id="listFeature_3" >
<option value="1" id="listFeature-0">Material Case </option>
<option value="2" id="listFeature-1">Thickness Case </option>
<option value="3" id="listFeature-2">Color Case</option>
<option value="4" id="featureList-4">Weight</option>
<option value="6" id="featureList-6">Models</option>
<option value="7" id="listFeature-7">Type Movement</option>
</select>
<select name="listFeature[]" id="listFeature_4" >
<option value="1" id="listFeature-0">Material Case </option>
<option value="2" id="listFeature-1">Thickness Case </option>
<option value="3" id="listFeature-2">Color Case</option>
<option value="4" id="featureList-4">Weight</option>
<option value="6" id="featureList-6">Models</option>
<option value="7" id="listFeature-7">Type Movement</option>
</select>

我需要处理一对选择选项和值输入。我在 $_POST["featureValue"] 中包含一个具有这些值的数组

$_POST["featureValue"][0]="Auto mechanic"
$_POST["featureValue"][1]="Steel"
$_POST["featureValue"][2]="Sport"
$_POST["featureValue"][3]=""

但是 $_Post["listFeature"] 只包含最后一个值

$_POST["listFeature"][0]= 2

与值关联

$_POST["featureValue"][3]=""

我需要

$_POST["listFeature"][0]= 7
$_POST["listFeature"][1]= 0
$_POST["listFeature"][2]= 6
$_POST["listFeature"][3]= 2

似乎对于选择选项来说,传递数组不起作用有人可以帮助我吗?

(使用谷歌翻译器翻译)

最佳答案

我验证了代码没问题。问题是,当您使用按钮添加功能创建新行时,先前的选择选项将被禁用。这意味着您不会传递选择选项禁用的值。为了解决这个问题,我禁用了选择选项的所有内部选项,仅保持所选选项的事件状态。然后我修改了代码

List = document.getElementById("listFeature_"+ id);List.setAttribute('禁用', '禁用');

var option =document.getElementById("listFeature").getElementsByTagName("option"); for (var i = 0; i < op.length; i++) { (选项[i].已选择)?选项[i].disabled = false : 选项[i].disabled = true ; }

现在似乎如我所愿

关于javascript - 表单中的多选选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40885251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com