数值控制
Elementor 数值控件显示一个简单的数字输入字段,可选择限制最小值和最大值,并定义数值变化时的步长。
该控件在继承 Base_Data_Control 类的 Control_Number 类中定义。
使用此控件时,应将 type 设置为 \Elementor\Controls_Manager::NUMBER 常量。
参数
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
type |
string |
number | 控件的类型。 |
label |
string |
显示在字段上方的标签。 | |
description |
string |
显示在字段下方的描述。 | |
show_label |
bool |
true | 是否显示标签。 |
label_block |
bool |
false | 是否在单独一行显示标签。 |
separator |
string |
default | 设置控件分隔符的位置。可用值为 default、before 和 after。default 将隐藏分隔符,除非控件类型有特定的分隔符设置。before / after 将分隔符定位在控件之前/之后。 |
min |
string |
最小值(仅影响微调器,用户仍可输入更低的值)。 | |
max |
string |
最大值(仅影响微调器,用户仍可输入更高的值)。 | |
step |
string |
使用控件微调器时递增或递减的间隔值。默认为空,值将递增 1。 | |
placeholder |
string |
字段无值时显示的占位符。 | |
title |
string |
鼠标悬停时显示的字段标题。 | |
default |
string |
字段的默认值。 |
Return Value
(string) The number field value.
Usage
<?php
class Elementor_Test_Widget extends \Elementor\Widget_Base {
protected function register_controls(): void {
$this->start_controls_section(
'content_section',
[
'label' => esc_html__( 'Content', 'textdomain' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'price',
[
'label' => esc_html__( 'Price', 'textdomain' ),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 5,
'max' => 100,
'step' => 5,
'default' => 10,
]
);
$this->end_controls_section();
}
protected function render(): void {
$settings = $this->get_settings_for_display();
if ( empty( $settings['price'] ) ) {
return;
}
?>
<span class="price">
<?php echo $settings['price']; ?>
</span>
<?php
}
protected function content_template(): void {
?>
<#
if ( '' === settings.price ) {
return;
}
#>
<span class="price">
{{{ settings.price }}}
</span>
<?php
}
}
这篇文档对你有帮助吗?
谢谢你的反馈!