我正在制作列表时出现问题。我想在下拉框中回显一个for循环的值,但是当这样做时,它会将它全部回显到一行,就像这样。
看看我的代码是什么样的
<select style="width: 183px;" name="timee" id="timee">
<?php
$timee = '';
for ($i = 0; $i <= 24; $i++) {
if($i <= 0) {
$timee .= $i;
}else {
$timee .= str_pad($i, 2, "0", STR_PAD_LEFT);
}
}
?>
<option value="<?php echo $timee; ?>">
<?php echo $timee; ?>
</option>
</select>
任何帮助都会非常感激,因为我对它的含义感到有点难过......像往常一样它可能就像地狱一样简单。
答案 0 :(得分:0)
在循环结束后打印所有输出,而你需要做的是每次循环迭代打印一个值:
<select style="width: 183px;" name="timee" id="timee">
<?php
// make sure to check which values should $timee get
for ($i = 0; $i <= 24; $i++) {
if ($i <= 0) {
$timee = $i;
} else {
$timee = str_pad($i, 2, "0", STR_PAD_LEFT);
}
?><option value="<?php echo $timee; ?>">
<?php echo $timee; ?>
</option><?php
}
?>
</select>
答案 1 :(得分:0)
如果您希望每个值都作为下拉列表中的单独选项:
var backwards : Bool = false
func timerAction(){
let Range = slider.maximumValue - slider.minimumValue;
let Increment = Range/100;
var newval = slider.value + Increment;
if(slider.value != slider.maximumValue && backwards == false){ //then slider is moving forwards
slider.setValue(newval, animated: true)
}
else if (slider.value == slider.maximumValue){ //slider needs to turn around
backwards = true
slider.setValue(slider.value - Increment, animated: true)
}
else if (slider.value == slider.minimumValue){ //slider needs to turn around
backwards = false
slider.setValue(slider.value + Increment, animated: true)
}
else if (backwards == true){ //slider is moving backwards
slider.setValue(slider.value + Increment, animated: true)
}
sliderValue = Int(slider.value)
}
此方法在列表中创建元素,并仅发出一个$options = '';
$timee = '';
for ($i = 0; $i <= 24; $i++) {
if($i <= 0) {
$timee = $i;
}else {
$timee = str_pad($i, 2, "0", STR_PAD_LEFT);
}
$options .= '<option value="' . $timee .'">' . $timee . '</option>';
}
echo '<select style="width: 183px;" name="timee" id="timee">' . $options . '</select>';
输出。以这种方式进行编码是理想的,因为它可以缩短客户端查看服务器响应所需的时间,因为服务器处理信息的速度比制作一堆StdOut调用更快。