在前端页面使用日历控件

网上各种Calendar、DatePicker令人眼花缭乱,但是成熟度相差很大,有的没有本地化、有的响应速度慢。
由于Magento默认基于Prototype,所以我们选择范围主要限制在protoype上建立的日历控件,感觉免费的prototype日历控件并不多好找。

如果进入Magento后台,大家会看到有很多地方使用了calendar控件:
[img]http://dl.iteye.com/upload/attachment/467123/0e1718f1-1bac-38f9-8cb2-547f54d47f05.png[/img]


Magento选择的这个Calendar比较完善,使用的是开源项目:http://www.dynarch.com/projects/calendar/
前台如果想使用它需要载入如下js和css
<reference name="head">
<action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
</reference>


然后载入本地化js,Magento对其进行了封装,为一个html文件,将后台使用的模板文件复制一份到前台模板目录(calendar.phtml)
<reference name="content">
<block type="core/html_calendar" name="head.calendar" as="calendar" template="page/js/calendar.phtml"/>
</reference>


这样代码中就可以使用它了
<input type="text" name="birthday" id="birthday" value="" class="input-text" />
<img src="<?php echo $this->getSkinUrl('images/grid-cal.gif') ?>" id="birthday-trig" />
<script type="text/javascript">
//<![CDATA[
Calendar.setup({
inputField: "birthday",
ifFormat: "%Y-%m-%d",
showsTime: false,
button: "birthday-trig",
align: "Bl",
singleClick : true
});
//]]>
</script>


仔细看上面的代码是如何将image和input对象绑定的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值