Re: [請益] 請問我的下拉選單,如何讓1-9月前面補0
※ 引述《Jyie (羽球小班)》之銘言:
: 小弟我想要1-9月前面補0,又想讓月份一開始停在系統當時月份
: 拜google大神找到以下兩種方法↓
: 可是有了這個沒了那個,有了那個沒了這個= =''
: 請問大大們有沒有方法能滿足我的慾望?
: 能讓我左擁這個,右抱那個。
讓你左擁右抱:
[load_date_option.php]
<?php
function load_year(){
return load_number("Y",date("Y"),1900);
}
function load_month(){
return load_number("m",12);
}
function load_date(){
return load_number("d",31);
}
function load_number($ymd,$number,$start = 1){
for($i = $start;$i <= $number;$i++){
$calendar = (($i <10)?"0":"").$i;
$selected = ($calendar == date($ymd))?"selected":"";
$option .= "<option value='{$calendar}' {$selected}>{$calendar}
</option>";
}
return $option;
}
?>
[your php file]
<?php
require("load_date_option.php");
?>
<select name="year_form">
<?=load_year()?>
</select>年
<select name="month_form">
<?=load_month()?>
</select>月
<select name="date_form">
<?=load_date()?>
</select>日
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.167.138.49
→
07/01 11:29, , 1F
07/01 11:29, 1F
※ 編輯: tkdmaf 來自: 218.167.138.49 (07/01 11:29)
→
07/01 11:30, , 2F
07/01 11:30, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章