看板 Ajax 關於我們 聯絡資訊
※ 引述《dedek (我要快樂起來)》之銘言: : 各位前輩下面一段程式 : endtime這個變數丟給new Date後,在IE6上面執行沒問題, : 但是到了kkman或是IE7後,丟進去的資料到了 endtimedate就會是空值 : 想了好久 還是找不到原因,所以上來問問前輩 : 請問這要怎麼處理比較好? : 這段程式最主要是判斷textbox4的日期 不能比textbox3早 : var endtime = document.getElementById("TextBox4").value; : var starttime = document.getElementById("TextBox3").value; 果然是因為字串格式的問題 , fx 是不吃 yyyy-mm-dd 的 , 手動自己做個 replace - , / 的行為換成 yyyy/mm/dd 吧。 endtime=endtime.replace(/-/gi,"/"); starttime=starttime.replace(/-/gi,"/"); 換完之後如果還有問題再丟新的error format上來. : var endtimedate = new Date(endtime); : var starttimedat=new Date(starttime); : var compare = Date.parse(endtimedate.toString()) - Date.parse(starttimedat.toS : tring()) - Date.parse(starttimedat.toString()); : var comday = compare / (1000 * 60 * 24*60); -- I am a person, and I am always thinking . Thinking in love , Thinking in life , Thinking in why , Thinking in worth. I can't believe any of what , I am just thinking then thinking , but worst of all , most of mine is thinking not actioning... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 74.207.224.18
dedek:謝謝T大幫忙!想問 同一隻程式不同瀏覽器,日期格式會不一樣? 01/28 11:41
dedek:我是用月曆function 選擇日期,到textbox 01/28 11:51
dedek:不同瀏覽器選擇出來的格式會不一樣! 01/28 11:52
dedek:感謝T大幫忙謝謝謝謝 01/28 11:52
neversay:如果允許的話,輸入GMT格式保證不會有問題 01/28 15:53
neversay:Wed Dec 2 2009 19:13:49 GMT+0800 01/28 15:53
neversay:這樣一定任何瀏覽器都吃~~~ 01/28 15:54
dedek:感謝感謝 01/29 22:08