gpt4 book ai didi

javascript - 在文本更正时,触发事件。可能的?

转载 作者:行者123 更新时间:2023-12-04 01:05:49 25 4
gpt4 key购买 nike

假设我有两个 textarea html 元素,我在一个中输入的内容显示在另一个中。

是否有一个 javascript 事件会在下面的屏幕截图中选择正确的单词时触发?

image1

最佳答案

无法从事件中获取此信息。您可以编写自己的“逻辑”,通过检查 change 事件来检测任何单词更改。

使用 split()filter() 函数检查更改后的单词的小示例:

function inputChange(event, oldvalue) {

// Old words
const old = oldvalue.split(' ');

// Current words
const curr = event.target.value.split(' ');

// Changed words
const diff = old.filter(x => !curr.includes(x));

// For each changed word
for (let changeId in diff) {

// Diff
console.log('Word changed: ', diff[changeId]);

// Optionally, you can get the same index, so you'll know the new value
const ind = old.indexOf(diff[changeId]);
console.log('New value: ', curr[ind]);
}
}
input { width: 300px; }
<input type='textarea' value='Test txt. Correct this: hoube -> house' onfocus="this.oldvalue = this.value;" onchange="inputChange(event, oldvalue)" />


关于javascript - 在文本更正时,触发事件。可能的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66519042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com