OpenHarmony开发者论坛

标题: 在鸿蒙系统中,哪个方法用于获取Text组件的内容? [打印本页]

作者: Rayner    时间: 2024-9-22 08:11
标题: 在鸿蒙系统中,哪个方法用于获取Text组件的内容?
这题的选项有点疑惑,希望有人能够解答!
(, 下载次数: 5)

作者: 鸿蒙小语哥    时间: 2024-9-23 09:48
  1. import { Text } from '@ohos.arkui'; // 引入文本组件

  2. // 创建一个Text组件
  3. const textComponent = new Text({
  4.   text: 'Hello, OpenHarmony!', // 初始内容
  5. });

  6. // 绑定到UI元素上
  7. this.view.addChild(textComponent);

  8. // 获取文本内容
  9. let content = textComponent.getText(); // 这将返回 "Hello, OpenHarmony!"
复制代码





欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5