问题描述
我正在 WooCommerce 中使用名为 woocommerce_form_field()
的函数为输入类型数字字段制作输入表单,如下所示:
woocommerce_form_field(
'left_far',array(
'type' => 'number','class' => array('left_far','left_far woocommerce-form-row woocommerce-form-row--last form-row form-row-last'),'required' => false,'label' => 'OOOOO',),get_user_Meta(get_current_user_id(),'left_far',true)
);
现在我希望能够允许在此字段中输入十进制浮点数。是否有可能?我该怎么办?
解决方法
您需要使用 'custom_attributes'
参数并将属性 'step'
设置为 'any'
,如下所示:
woocommerce_form_field( 'left_far',array(
'type' => 'number','label' => 'OOOOO','class' => array('left_far','left_far woocommerce-form-row woocommerce-form-row--last form-row form-row-last'),'custom_attributes' => array( 'step' => 'any','min' => '0' ),'required' => false,),get_user_meta( get_current_user_id(),'left_far',true ) );
经过测试并有效。
注意: 'min'
参数定义起始允许值