我有这段代码
<?php $json = json_encode($question->varz); ?>
@section('script')
<script type="text/javascript">
const nameSelect = $('<select></select>');
const person1 = $(' @foreach($question->answers as $answer)@if($answer->drop_down_owner==0) <option value="person1"> {{$answer->text}}</option> @endif @endforeach');
nameSelect.append(person1);
const ageSelect = $('<select></select>');
const age1 = $(' @foreach($question->answers as $answer)@if($answer->drop_down_owner==1) <option value="person1"> {{$answer->text}}</option> @endif @endforeach');
ageSelect.append(age1);
var json = <?php echo $json; ?>;
const dropdown = [ nameSelect, ageSelect];
for (var i = 0; i < json.length; i++)
{
if(json[i] != "#KDPOPTION"){
$('#dropdowns').append(json[i]);
}else
{
$('#dropdowns').append($(dropdown[0]));
}
}
</script>
,结果为IamandIam[appears the dropdown]yearsold
。我需要下拉列表出现在像这样的两个地方
Iam[appears the dropdown]andIam[appears the dropdown]yearsold.
所以,如果我按<4,则下拉列表出现在第一位,如果i <7或更大,则下拉列表仅出现在最后一个位置。