对于文本输入,如何让它点击它会select一切?
For text input, how to make it so that clicking on it will select everything?
我找到了这个:Copy to Clipboard that also works on Mobile?
但是 VueJS 不使用 jQuery。那么有什么替代方案呢?
您仍然可以使用 JQuery,只需将脚本添加到您的 HTML,但如果您不想使用 JQuery,替代方案是使用 vanilla [=21] =](纯 JS)。
输入的setSelectionRange(start, end)
方法就是您想要的答案。
这是一个演示。
<input type="text" ref="input" @click="selectAll">
selectAll() {
this.$refs.input.select();
}
基于 https://medium.com/vuejs-tips/tip-11-auto-select-input-text-on-focus-9eca645073cd 文章:
<input @focus="$event.target.select()">
我找到了这个:Copy to Clipboard that also works on Mobile?
但是 VueJS 不使用 jQuery。那么有什么替代方案呢?
您仍然可以使用 JQuery,只需将脚本添加到您的 HTML,但如果您不想使用 JQuery,替代方案是使用 vanilla [=21] =](纯 JS)。
输入的setSelectionRange(start, end)
方法就是您想要的答案。
这是一个演示。
<input type="text" ref="input" @click="selectAll">
selectAll() {
this.$refs.input.select();
}
基于 https://medium.com/vuejs-tips/tip-11-auto-select-input-text-on-focus-9eca645073cd 文章:
<input @focus="$event.target.select()">