PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

Magento后台表单元素标签2--显示日期

原创
2016-07-29 08:58:17 984浏览

功能介绍:今天要做一个后台表单元素显示出日期时间,开始以为跟magento后台用到的表单元素标签(1)的功能一样,只需要设置type类型设置为date就可,但是设置了,开始怎么也弄不出来,又想着在后台加载一些js包,引用外部的js插件来实现这个功能,后来请教公司技术牛人,说可以直接调用magento系统自带的就可以,这里记录下如何实现这个功能,效果图如下:

代码如下,在form.php中增加代码如下:

<code>$fieldset->addField(
        'endtime',
        'date',//type类型
         array(
            'label'     => Mage::helper('blog')->__('Endtime'),
            'required'  => true,//是否为必选项
            'name'      => 'endtime',
            'image'  => $this->getSkinUrl('images/grid-cal.gif'),//增加图标
            'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),//时间格式
));</code>

额外的一些备注:
1.有时候如果想在后台表单加载一些js,也可以在array()中添加:'after_element_html' => ""。

2.添加css,可以先在外写好css样式,$style="width:6px;text-align:center;"再添加:'style'=> $style,//定义按钮的css 。也可以直接写,例如:'style' => 'width:700px; height:500px;'。

<code>$fieldset->addField(
        'endtime',
        'date',//类型,可以为text,datetime,time,submit,select,radio,checkbox,password,link,label,image,file...
         array(
                'label'     => Mage::helper('blog')->__('Endtime'),
                'required'  => true,//是否为必选项
                'style'=> $style,//定义按钮的css .
                'name'      => 'endtime',
                'image'  => $this->getSkinUrl('images/grid-cal.gif'),//添加图片
                'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
                'after_element_html' => "<script type="text/javascript">//js代码</script>"。
        ));</code>

以上就介绍了Magento后台表单元素标签2--显示日期,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。