http://10.10.55.25/test/index.php?getdate=2018&getdate=05
我有2个下拉选项。年和月。我单击搜索后的结果是“ getdate = 2018&getdate = 05”,但我希望结果是“ getdate = 201805”
<?php
echo "<select name=getdate>";
for($i=0;$i<=11;$i++)
{
$year=date('Y',strtotime("last day of -$i year"));
echo "<option>$year</option>";
}
echo "</select>";
echo "<select name=getdate>";
for($i=0;$i<=11;$i++){
$month=date('m',strtotime("first day of -$i month"));
echo "<option>$month</option> ";
}
echo "</select>";
?>
<button type="submit" class="btn"><?php echo "Search";?></button>
答案 0 :(得分:0)
您需要隐藏输入和JS来连接年份和月份的值
PHP
<?php
echo "<select id='year'>";
for($i=0;$i<=11;$i++)
{
$year=date('Y',strtotime("last day of -$i year"));
echo "<option>$year</option>";
}
echo "</select>";
echo "<select id='month'>";
for($i=0;$i<=11;$i++){
$month=date('m',strtotime("first day of -$i month"));
echo "<option>$month</option> ";
}
echo "</select>";
?>
<input type="hidden" name="getdate">
<button type="submit" class="btn"><?php echo "Search";?></button>
JS
<script type="text/javascript">
$('select#year, select#month').change(function() {
yr = $('select#year option:selected').text();
mnth = $('select#month option:selected').text();
$('input[name="getdate"]').val(yr+""+mnth);
});
</script>