[請益] "select" & "selected" 的問題

看板PHP作者 (不要找我估價( ′-`)y-~)時間17年前 (2008/06/07 09:44), 編輯推噓3(303)
留言6則, 4人參與, 最新討論串1/1
標題不知如何命名才好 = =" -- 想法:用 select 做生日選項,選取完年、月後自動判斷正確的日數。 描述:因為每個月的天數不同,還有二月的問題,因此希望在使用者選取完年、月之後, 讓天數的部份可以正確的呈現出來。 作法: function add_form($get_year="", $get_month="", $get_day="") { if(!empty($get_year)) $_SESSION['year'] = $get_year; if(!empty($get_month)) $_SESSION['month'] = $get_month; if(!empty($get_day)) $_SESSION['day'] = $get_day; $birthday = "<select name='birthday['year']' onchange='window.location=this.value;'>"; $birthday .= "<option>年</option>"; for($i=65; $i<86; $i++) { $selected = ''; if($_SESSION['year'] == $i) $selected = 'selected'; $birthday .= "<option value='?action=add_form&year={$i}' $selected>$i 年 </option>"; } $birthday .= "</select>"; } 當使用者選完年之後,會再次跳入本頁面,同時將該年呈現已選取的狀態, 並寫入 SESSION 中。(表格完成後才將該SESSION UNREGISTER掉) 月的部份和年一樣,只是在年和月都選取完後會判斷該月份的天數。 實際網頁: http://220.132.228.88 帳號密碼: guest//guest 登入後請選擇 "通訊錄" => "新增" 即可看到。 忘記提出問題了 囧> 我想請教的是,一般在寫這個部份時, 用的是什麼方法? -- 方便的話,也請到 "意見反應" 留下您保貴的意見 :) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.228.88 ※ 編輯: passers 來自: 220.132.228.88 (06/07 11:43)

06/07 20:14, , 1F
比較推用Javascript+DOM...
06/07 20:14, 1F

06/08 01:44, , 2F
推1樓,畢竟選個日期還要換頁,太浪費server資源了
06/08 01:44, 2F

06/08 21:39, , 3F
06/08 21:39, 3F

06/08 21:40, , 5F
上面是 demo
06/08 21:40, 5F

06/09 05:30, , 6F
酷!等有空來研究看看(搬家ing)
06/09 05:30, 6F
文章代碼(AID): #18IUVg23 (PHP)
文章代碼(AID): #18IUVg23 (PHP)