Input 组件 内容为 '去 ————办公' 只获取横线上的内容,不需要e.target.value
时间: 2024-06-14 12:07:13 浏览: 10
根据提供的引用内容,你可以使用以下方法来获取输入组件中横线上的内容,而不需要使用`e.target.value`:
1. 使用正则表达式提取横线上的内容:
```javascript
const inputContent = '去 ————办公';
const regex = /—+([^—]+)—+/;
const match = inputContent.match(regex);
const content = match ? match[1].trim() : '';
console.log(content); // 输出:办公
```
2. 使用字符串的`split()`方法和数组的`filter()`方法提取横线上的内容:
```javascript
const inputContent = '去 ————办公';
const content = inputContent.split('——').filter((item, index) => index === 1)[0].trim();
console.log(content); // 输出:办公
```
3. 使用字符串的`replace()`方法去除横线,然后使用`trim()`方法去除空格提取横线上的内容:
```javascript
const inputContent = '去 ————办公';
const content = inputContent.replace(/—+/g, '').trim();
console.log(content); // 输出:办公
```