magento 出生日期下拉框 customer dob

magento 出生日期下拉框

dob

template/customer/widget  dob.phtml

<label for="<?php echo $this->getFieldId('month')?>"<?php if ($this->isRequired()) echo ' class="required"' ?>><?php if ($this->isRequired()) echo '<em>*</em>' ?><?php echo $this->__('Date of Birth') ?></label>
<div class="input-box customer-dob">
<?php
// days
echo "<select id=\"sDay\" name=\"sDay\" rel=\"".str_replace(":","\:",$this->getFieldId('day'))."\" class=\"dateselect\">";
$selected = (!$this->getDay()) ? "selected=\"selected\"" : "";
echo "<option value=\"\" ".$selected.">Day</option>";
for ($i = 1; $i <= 31; $i++) {
$ti = str_pad($i, 2, "0", STR_PAD_LEFT);
$selected = ($this->getDay() == $ti) ? "selected=\"selected\"" : "";
echo "<option value=\"".$ti."\" ".$selected.">".$i."</option>";
}
echo "</select>";
?>

<?php
// months
$months = array(
'01'=>'一月',
'02'=>'二月',
'03'=>'March',
'04'=>'April',
'05'=>'May',
'06'=>'June',
'07'=>'July',
'08'=>'August',
'09'=>'September',
'10'=>'October',
'11'=>'November',
'12'=>'December',
);
echo "<select id=\"sMonth\" name=\"sMonth\" rel=\"".str_replace(":","\:",$this->getFieldId('month'))."\" class=\"dateselect\">";
$selected = (!$this->getMonth()) ? "selected=\"selected\"" : "";
echo "<option value=\"\" ".$selected.">Month</option>";
foreach ($months as $key=>$var)
{
$selected = ($this->getMonth() == $key) ? "selected=\"selected\"" : "";
echo "<option value=\"".$key."\" ".$selected.">".$var."</option>";
}
echo "</select>";
?>

<?php
// years
$year_end = date('Y');
$year_start = $year_end-99;
echo "<select id=\"sYear\" name=\"sYear\" rel=\"".str_replace(":","\:",$this->getFieldId('year'))."\" class=\"dateselect\">";
$selected = (!$this->getYear()) ? "selected=\"selected\"" : "";
echo "<option value=\"\" ".$selected.">Year</option>";
for ($i = $year_end; $i >= $year_start; $i--) {
$selected = ($this->getYear() == $i) ? "selected=\"selected\"" : "";
echo "<option value=\"".$i."\" ".$selected.">".$i."</option>";
}
echo "</select>";

?>
<div class="input-box customer-dob">

<div class="dob-full" style="display:none;">
<?php echo ' <div class="dob-day">
<input type="hidden" id="' . $this->getFieldId('day') . '" name="' . $this->getFieldName('day') . '" value="' . $this->getDay() . '" title="' . $this->__('Day') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
<label for="' . $this->getFieldId('day') . '">' . $this->__('DD') . '</label>
</div>';?>
<?php echo '
<div class="dob-month">
<input type="hidden" id="' . $this->getFieldId('month') . '" name="' . $this->getFieldName('month') . '" value="' . $this->getMonth() . '" title="' . $this->__('Month') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
<label for="' . $this->getFieldId('month') . '">' . $this->__('MM') . '</label>
</div>'; ?>
<?php echo '
<div class="dob-year">
<input type="hidden" id="' . $this->getFieldId('year') . '" name="' . $this->getFieldName('year') . '" value="' . $this->getYear() . '" title="' . $this->__('Year') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
<label for="' . $this->getFieldId('year') . '">' . $this->__('YYYY') . '</label>
</div>';
?>

<div class="validation-advice" style="display:none;"></div>
</div>
<div class="dob-full" style="display:none;">
<input type="hidden" id="<?php echo $this->getFieldId('dob')?>" name="<?php echo $this->getFieldName('dob')?>" />
</div>

<script type="text/javascript">
//<![CDATA[

var customer_dob = new Varien.DOB('.customer-dob', <?php echo $this->isRequired() ? 'true' : 'false' ?>, '<?php echo $this->getDateFormat() ?>');
jQuery(document).ready(function() {
//加载到hidden input值
jQuery( ".dateselect" ).each(function() {
related_field_id = jQuery(this).attr('rel');
current_value = jQuery( "#"+related_field_id ).val();
jQuery(this).val(current_value);
});
jQuery( "#<?php echo str_replace(":","\:",$this->getFieldId('dob'));?>" ).val(jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('year'));?>").val()+'-'+jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('month'));?>").val()+'-'+jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('day'));?>").val());
// 给dob赋值
jQuery( ".dateselect" ).change(function() {
current_value = jQuery(this).val();
related_field_id = jQuery(this).attr('rel');
jQuery( "#"+related_field_id ).val(current_value);
jQuery( "#<?php echo str_replace(":","\:",$this->getFieldId('dob'));?>" ).val(jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('year'));?>").val()+'-'+jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('month'));?>").val()+'-'+jQuery("#<?php echo str_replace(":","\:",$this->getFieldId('day'));?>").val());
});
});

//]]>
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值