js:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function Myselect_txt(){
if (document.form1.title.focus){
document.form1.title.select();}
}
function Myselect_txtarea(){
if (document.form1.content.focus){
document.form1.content.select();}
}
function selectInput(){
if (document.form1.title.focus){
document.form1.title.select();
}
}
function selectArea(){
if (document.form1.content.focus){
document.form1.content.select();
}
}
</script>
</head>
<body style="font-size:12px">
<form name="form1">
<input name="title" type="text" size="50" value="选中input文字" onClick="selectInput()">
<textarea name="content" cols="50" rows="6" onClick="selectArea()">选中textarea文字</textarea>
</form>
</body>
</html>
vue:
<template>
<div class="app-container">
<el-input v-model="aa" type="text" ref="aaRef" @focus="aaFocus()" size="mini"></el-input>
</div>
</template>
<script>
data() {
return {
aa: '1231312341231',
}
},
methods: {
aaFocus() {
const inputEle = this.$refs['aaRef']
inputEle.select()
},
}
</script>