【问题标题】:how to get cursor position of a div element in vue js?如何在vue js中获取div元素的光标位置?
【发布时间】:2021-01-26 14:37:41
【问题描述】:

我只能获取 input 和 textarea 元素的光标位置,但是如何处理包含 contenteditable = "true" 的 div 元素呢?

getCursor() {
      const text = this.$refs.test;
      const value = text.selectionStart;
      console.log(value); // result is undefined
    }
<div
  ref="test"
  contenteditable="true"
  :v-html="inputIntegrationHMTL"
  @input="getCursor($event)"
 > </div>

【问题讨论】:

标签: javascript vue.js


【解决方案1】:

像这样?

getCursor(event) {
      console.log(event); // you can read pos here
}
<div
  ref="test"
  contenteditable="true"
  :v-html="inputIntegrationHMTL"
  @mouseover="getCursor($event)"
 > </div>

【讨论】:

猜你喜欢
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-04
相关资源
最近更新 更多