我正在用动态形式编写HTML脚本,并且单选按钮存在一些问题。
我试图将“ name ='some []'”更改为“ name ='some'”,并将“ id”更改为其他名称。
在视图中:
$nam = $this - > input - > post("name", TRUE);
$jek = $this - > input - > post("sex", TRUE);
$hub = $this - > input - > post("hub", TRUE);
for ($x = 0; $x < sizeof($nam); $x++) {
$array[] = array('name' => $nam[$x], 'sex' => $jek[$x], 'hub' => $hub[$x]);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<div class="form-group">
<label class="col-md-4 control-label">Sex</label>
<div class="col-md-8 inputGroupContainer">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-default active">
<input type="radio" name="sex[]" value="0"> Female
</label>
<label class="btn btn-default">
<input type="radio" name="sex[]" value="1"> Male
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Kinship</label>
<div class="col-md-8 inputGroupContainer">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-default active">
<input type="radio" name="hub[]"> Wife
</label>
<label class="btn btn-default">
<input type="radio" name="hub[]"> Daughter/Son
</label>
<label class="btn btn-default">
<input type="radio" name="hub[]"> Other
</label>
</div>
</div>
</div>
结果是:
$nam = $this - > input - > post("name", TRUE);
$jek = $this - > input - > post("sex", TRUE);
$hub = $this - > input - > post("hub", TRUE);
for ($x = 0; $x < sizeof($nam); $x++) {
$array[] = array('name' => $nam[$x], 'sex' => $jek[$x], 'hub' => $hub[$x]);
}
当我选择时:
sex = 0,hub = wife
sex = 1,hub = daughter / son