允许 WooCommerce 表单字段类型编号中的十进制浮点数

问题描述

我正在 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' 参数定义起始允许值

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...