在下面的这段代码中,我首先使用了 javascript 代码进行下拉,当我更新时,只有第一行得到更新,其余的没有更新。接下来我使用 html 代码更新了所有行,请任何人帮助解决这个问题。我从 html 更改为 js 的原因是为了汽车年。
<script type="text/javascript">
function autoYear() {
var time = new Date();
var year = time.getYear();
if (year < 1900) {
year = year + 1900;
}
var date = year - 1; /*change the '25' to the number of years in the past you want to show */
var future = year + 10; /*change the '10' to the number of years in the future you want to show */
document.writeln ("<form><select id='year_<?php echo $row->id ?>' name='year_<?php echo $row->id ?>' ><option value=\"\"><?php echo $row->year; ?>");
do {
date++;
if (date != <?php echo $row->year; ?>) {
document.write ("<option value=\"" +date+"\">" +date+ "");
}
}
while (date < future);
document.write ("</select></form>");
}
</script>
<script type="text/javascript">
autoYear();
</script>
html
<select class="inputmedium" name="year_<?php echo $row->id; ?>" id="year_<?php echo $row->id; ?>" value="<?php echo $row->year; ?>">
<?php for($s=0;$s<8;$s++)
{
if($row->year!=null and $row->year==$year_array[$s]){
echo "<option selected value='" .$year_array[$s]. "'>" .$year_array[$s]. "</option>";
}else{
echo "<option value='" .$year_array[$s]. "'>" .$year_array[$s]. "</option>";
}
} ?>
</select>
<?php
$year_array=array();
$year_array[0]="2013";
$year_array[1]="2014";
$year_array[2]="2015";
$year_array[3]="2016";
$year_array[4]="2017";
$year_array[5]="2018";
$year_array[6]="2019";
$year_array[7]="2020";
?>