【问题标题】:Select entire cell text on single click for cell edit instead of double click in primeng table单击选择整个单元格文本以进行单元格编辑,而不是在primeng表中双击
【发布时间】:2021-03-08 01:08:18
【问题描述】:

我正在使用一个 p 表,其中的单元格填充了整数数据并且是可编辑的。现在单击一下,输入文本变为可见,光标位于单元格文本的末尾。要求是在单击编辑本身时选择单元格文本的全部内容。基本上单击应该像双击一样。我在 app.component.html 中添加了 2 个事件作为输入:

(focus)="focusInFunction($event)"
(dblclick)="eventEmitDoubleClick($event)"

但是仅仅从 focusInFunction() 函数调用 eventEmitDoubleClick() 是行不通的。

【问题讨论】:

  • 你能创建一个 StackBlitz 吗?
  • (focus)="$event.preventDefault();focusInFunction($event)" 不起作用?
  • 我添加了 (focus)="$event.preventDefault();focusInFunction($event)" 并从 focusInFunction(event) 函数调用 this.eventEmitDoubleClick(event)。但仍然没有运气。

标签: css angular typescript primeng primeng-turbotable


【解决方案1】:

在这里你可以尝试这样的事情:

$('#highlight').on('click', function() {
  var Target = document.getElementById("highlight");
  Target.select();
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" value="hello world" id="highlight">

【讨论】:

  • 是的,这行得通。只需将 Target 声明调整为: var Target = document.getElementById("highlight") as HTMLInputElement;
猜你喜欢
  • 2014-05-08
  • 2023-01-14
  • 2011-03-18
  • 1970-01-01
  • 2016-01-08
  • 2014-12-05
  • 2013-05-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多