getElementById不从javascript函数中的文本区域返回当前文本
My function document.getelementbyid未从HTML页面返回textarea的当前值 HTML: 在文本区域中,我可以编辑现有值并将修改后的值保存到DB中 当点击“保存描述”按钮时,它返回第一个元素,该元素正在传递到文本区域,但需要获取文本区域的当前值getElementById不从javascript函数中的文本区域返回当前文本,javascript,html,Javascript,Html,My function document.getelementbyid未从HTML页面返回textarea的当前值 HTML: 在文本区域中,我可以编辑现有值并将修改后的值保存到DB中 当点击“保存描述”按钮时,它返回第一个元素,该元素正在传递到文本区域,但需要获取文本区域的当前值 onClick="updateDescription('<%=person[\'person_name\']%>')" 您在onclick中的报价不会被转义: <button name="butt
onClick="updateDescription('<%=person[\'person_name\']%>')"
您在onclick中的报价不会被转义:
<button name="button" type="button" class="save" class="btn btn-info" onClick="updateDescription('<%=person[\'person_name\']%>')">save description</button>
当文档加载时,您的文本区域仍然为空,它会在警报时显示为空。您需要通过person\u descr设置值。value=person\u name
函数updateDescriptionperson\u名称{
变量person\u name=person\u name
var person\u descr=document.getElementByIdperson\u descr;
警员姓名
警报人员描述值;
person\u descr.value=人名;
警报人员描述值
}
人名
aaa
人物描述
保存描述
要获取html文本区域值,可以使用value属性:
document.getElementById("id").value
此外,您还必须转义html引号:
<button name="button" type="button" class="save"
class="btn btn-info"
onClick="updateDescription('<%=person[\'person_name\']%>')">
save description </button>
避免-use-or的限制和笨拙语法。下面的演示使用OneEvent属性 顺便说一句,按钮无效,它有两个类属性: 保存描述 演示 document.querySelector.btn.onclick=updateDesc; 函数updateDesce{ var personName=document.getElementByIdpersonName; var personDesc=document.getElementByIdpersonDesc; console.logpersonName.textContent; console.logpersonesc.value; } * { 保证金:0; 填充:0 } 人名 无名氏 人物描述 保存描述
您有多个textarea元素,对吗?他们都有相同的身份证…?我把它弄错了。没问题。你的产出是多少?寻求调试帮助的问题此代码为什么不起作用?必须包括所需的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。请参见:如何创建。
document.getElementById("id").value
<button name="button" type="button" class="save"
class="btn btn-info"
onClick="updateDescription('<%=person[\'person_name\']%>')">
save description </button>