Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何用textarea字段替换输入_Html - Fatal编程技术网

Html 如何用textarea字段替换输入

Html 如何用textarea字段替换输入,html,Html,我目前正在从事一个html5项目,其中有许多输入字段,我想用textarea替换 例如: <input type="text" id="Questions" name="texte1"/> <input type="text" id="Questions" name="texte2"/> <input type="text" id="Questions" name="texte3"/> 我想通过以下方式更改200个输入: <textarea id=

我目前正在从事一个html5项目,其中有许多
输入
字段,我想用
textarea
替换

例如:

<input type="text" id="Questions" name="texte1"/>
<input type="text" id="Questions" name="texte2"/>
<input type="text" id="Questions" name="texte3"/>

我想通过以下方式更改200个输入:

<textarea id="Questions" name="texte1"></textarea> 
<textarea id="Questions" name="texte2"></textarea> 
<textarea id="Questions" name="texte3"></textarea> 


但我不能真正使用搜索和替换工具,因为每个输入的名称都不同,所以我想知道你们是否知道一种快速方法,可以用文本区域替换我的所有输入,而不必在我的代码上逐个更改名称。

您需要一个标准来告诉您哪些输入需要替换。他们有什么共同点?还要注意,对于
id
,每页不能有多个具有相同值的元素,因此显示的HTML无效

因此,对于示例代码,我假设所有需要替换的输入都有一个CSS类
replace me

document.getElementById('replace').addEventListener('click',(e)=>{
const torerece=[…document.querySelectorAll('.replace me')]
for(存储替换的常量输入){
const textarea=document.createElement('textarea')
const parent=input.parentNode
textarea.id=input.id
textarea.name=input.name
textarea.value=input.value
parent.removeChild(输入)
parent.appendChild(textarea)
}  
})


单击以替换
您需要一个标准来告诉您哪些输入需要替换。他们有什么共同点?还要注意的是,对于
id
,每页不能有多个具有相同值的元素,因此显示的HTML无效。好的,谢谢,我应该使用class而不是id吗?除了名字不同之外,它们都有共同点。你试过使用哈巴狗吗?我没有,我会告诉我的谢谢。