For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/api/elements/built-in/textarea-API.md.
Lynx
  • 简体中文
  • 属性

    android-fullscreen-mode

    Android
    3.4
    // @默认值: true
    'android-fullscreen-mode'?: boolean;

    在横屏时是否进入全屏输入模式,在此模式下键盘和输入框将占据整个屏幕

    bounces

    iOS
    3.4
    // @默认值: true
    bounces?: boolean;

    iOS 的反弹效果

    confirm-type

    iOS
    Harmony
    3.4
    // @默认值: 'done'
    'confirm-type'?: 'search' | 'send' | 'go' | 'done' | 'next';

    确认按钮的类型

    disabled

    Android
    iOS
    Harmony
    3.5
    // @默认值: false
    disabled?: boolean;

    是否启用交互

    enable-scroll-bar

    Android
    iOS
    3.6
    // @默认值: false
    'enable-scroll-bar'?: boolean;

    是否显示滚动条,在鸿蒙系统上,滚动条将始终显示

    input-filter

    Android
    iOS
    Harmony
    3.4
    // @默认值: undefined
    'input-filter'?: string;

    过滤输入内容,并以正则表达式的形式进行处理

    ios-auto-correct

    iOS
    3.4
    // @默认值: true
    'ios-auto-correct'?: boolean;

    在 iOS 上自动纠正输入内容

    ios-spell-check

    iOS
    3.4
    // @默认值: true
    'ios-spell-check'?: boolean;

    在 iOS 上检查拼写问题

    line-spacing

    Android
    iOS
    3.4
    // @默认值: undefined
    'line-spacing'?: number | any | any;

    行间距

    maxlength

    Android
    iOS
    Harmony
    3.4
    // @默认值: 140
    maxlength?: number;

    最大输入长度

    maxlines

    Android
    iOS
    Harmony
    3.4
    // @默认值: undefined
    maxlines?: number;

    最大输入行数

    placeholder

    Android
    iOS
    Harmony
    3.4
    placeholder?: string;

    占位符

    readonly

    Android
    iOS
    Harmony
    3.4
    // @默认值: false
    readonly?: boolean;

    只读

    show-soft-input-on-focus

    Android
    iOS
    3.4
    // @默认值: true
    'show-soft-input-on-focus'?: boolean;

    聚焦时显示软输入键盘

    type

    Android
    iOS
    Harmony
    3.4
    // @默认值: "text"
    type?: 'number' | 'text' | 'digit' | 'tel' | 'email';

    输入内容类型

    事件

    前端可以绑定相应的事件回调来监听元素的运行时行为,如下所示。

    bindblur

    Android
    iOS
    Harmony
    3.4
    bindblur = (e: TextAreaBlurEvent) => {};
    字段类型是否可选默认值平台版本描述
    valuestring
    Android
    iOS
    Harmony
    3.4
    3.4输入内容

    失去焦点

    bindconfirm

    Android
    iOS
    Harmony
    3.4
    bindconfirm = (e: TextAreaConfirmEvent) => {};
    字段类型是否可选默认值平台版本描述
    valuestring
    Android
    iOS
    Harmony
    3.4
    3.4输入内容

    点击确认按钮,仅在定义了 confirm-type 时生效

    bindfocus

    Android
    iOS
    Harmony
    3.4
    bindfocus = (e: TextAreaFocusEvent) => {};
    字段类型是否可选默认值平台版本描述
    valuestring
    Android
    iOS
    Harmony
    3.4
    3.4输入内容

    获得焦点

    bindinput

    Android
    iOS
    Harmony
    3.4
    bindinput = (e: TextAreaInputEvent) => {};
    字段类型是否可选默认值平台版本描述
    isComposingboolean
    Android
    iOS
    Harmony
    3.4
    3.4是否正在输入
    selectionEndnumber
    Android
    iOS
    Harmony
    3.4
    3.4选中文本的结束位置
    selectionStartnumber
    Android
    iOS
    Harmony
    3.4
    3.4选中文本的起始位置
    valuestring
    Android
    iOS
    Harmony
    3.4
    3.4输入内容

    输入内容改变

    bindselection

    Android
    iOS
    Harmony
    3.4
    bindselection = (e: TextAreaSelectionChangeEvent) => {};
    字段类型是否可选默认值平台版本描述
    selectionEndnumber
    Android
    iOS
    Harmony
    3.4
    3.4选中文本的结束位置
    selectionStartnumber
    Android
    iOS
    Harmony
    3.4
    3.4选中文本的起始位置

    输入选中文本改变

    方法

    前端可以通过 SelectorQuery API 调用组件方法。

    blur

    Android
    iOS
    Harmony
    3.4
    
    lynx.createSelectorQuery()
         .select('#id')
         .invoke({
          method: 'blur',
          success: function (res) {},
          fail: function (res) {},
        })
        .exec();
    

    释放焦点

    focus

    Android
    iOS
    Harmony
    3.4
    
    lynx.createSelectorQuery()
         .select('#id')
         .invoke({
          method: 'focus',
          success: function (res) {},
          fail: function (res) {},
        })
        .exec();
    

    请求焦点

    getValue

    Android
    iOS
    Harmony
    3.4
    interface GetValueResult {
      /**
       * 是否正在输入,仅 iOS 支持
       * @Android
       * @iOS
       * @Harmony
       * @Web
       * @since 3.4
       */
      isComposing: boolean;
      /**
       * 光标结束位置
       * @Android
       * @iOS
       * @Harmony
       * @Web
       * @since 3.4
       */
      selectionEnd: number;
      /**
       * 光标开始位置
       * @Android
       * @iOS
       * @Harmony
       * @Web
       * @since 3.4
       */
      selectionStart: number;
      /**
       * 输入内容
       * @Android
       * @iOS
       * @Harmony
       * @Web
       * @since 3.4
       */
      value: string;
    }
    
    lynx.createSelectorQuery()
         .select('#id')
         .invoke({
          method: 'getValue',
          success: function (res: GetValueResult) {},
          fail: function (res) {},
        })
        .exec();
    

    获取输入内容

    setSelectionRange

    Android
    iOS
    Harmony
    3.4
    
    lynx.createSelectorQuery()
         .select('#id')
         .invoke({
          method: 'setSelectionRange',
          params: {
            /**
             * 选择区域的结束位置
             * @Android
             * @iOS
             * @Harmony
             * @Web
             * @since 3.4
             */
            selectionEnd: 5,
            /**
             * 选择区域的开始位置
             * @Android
             * @iOS
             * @Harmony
             * @Web
             * @since 3.4
             */
            selectionStart: 0,
          },
          success: function (res) {},
          fail: function (res) {},
        })
        .exec();
    

    设置选择区域

    setValue

    Android
    iOS
    Harmony
    3.4
    
    lynx.createSelectorQuery()
         .select('#id')
         .invoke({
          method: 'setValue',
          params: {
            /**
             * 输入内容
             * @Android
             * @iOS
             * @Harmony
             * @Web
             * @since 3.4
             */
            value: 'hello',
          },
          success: function (res) {},
          fail: function (res) {},
        })
        .exec();
    

    设置输入内容

    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。