gpt4 book ai didi

javascript - 如何复制文本的一部分,并使用 Jquery 填充输入

转载 作者:行者123 更新时间:2023-11-27 23:26:54 25 4
gpt4 key购买 nike

使用 Jquery 或 PHP 导入数据的最佳方式是什么。

我需要读取文本区域,并像这样识别 block

姓名:这是姓名,年龄:这是年龄我只需要获取名称之间的部分:我需要获取这个年龄:

我不知道怎么做,也不知道我需要用什么来做这个。所以我需要知道如何开始?

jquery 选择器,不重要,因为我可以使用任何类似更改或按钮单击功能的想法,这无关紧要...

<textarea id='import'>
this is pasted text...
name: this is name
age: this is age
other: have but i dont need
other2: have but i dont need
city: this is city
obs: this is obs </textarea>
<input type="text" id="name">
<input type="text" id="age">
<input type="text" id="city">
<input type="text" id="obs">
<button>Import</button>

最佳答案

您可以试试这个 javascript 代码:

var input = document.getElementById("import");

input.addEventListener('input', function(){
var content = input.value;

content.replace(/(\S+): ?(.+)/g, function(m, id, value) {
var element = document.getElementById(id);
if (element) element.value = value;
});
});
<textarea id="import"></textarea>
<br>name: <input type="text" id="name">
<br>age: <input type="text" id="age">
<br>city: <input type="text" id="city">
<br>obs: <input type="text" id="obs">

您可以在 action here. 中看到正则表达式

关于javascript - 如何复制文本的一部分,并使用 Jquery 填充输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38065303/

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