作者a007son (梦痕)
看板Flash
标题[问题] 这段脚本有更好的写法吗?
时间Sat Feb 6 20:16:38 2010
我在写时钟脚本(AS 2.0)的时候遇到这个问题
将24时制改成12时制,目前我的写法是这样:
hours = fscommand2("GetTimeHours");
if (hours < 10)
{
hours = hours;
hours = "0" add hours;
}
if (hours > 12)
{
hours = hours - 12 ;
hours = "0" add hours;
}
if (hours >22)
{
hours = hours - 12 ;
}
我觉得有点累赘,想用else或是else if来修改这段脚本
想请问大家要如何改写呢?
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.216.10.78
1F:推 cjcat2266:hours = ((hours > 12)?(hours - 12):hours).toString() 02/06 21:14
2F:→ cjcat2266:if (hours.length == 1) hours = "0" + hours; 02/06 21:14
3F:→ cjcat2266:其实你的写法没问题啊,只要第二个if以後 02/06 21:15
4F:→ cjcat2266:都改成else if就可以了 02/06 21:15
5F:→ a007son:所以使用if两个以上,後者都可以用else if表示吗? 02/06 21:19
6F:→ a007son:那麽while跟if的差别是? 02/06 21:20
7F:推 pm2001:if只执行一次 02/06 21:23
8F:→ a007son:谢谢楼上两位 02/07 08:51