我需要帮助。 我有下面的代码:脚本返回每个按钮的 id。
之后,我需要在 Wordpress 中的联系表单 7 生成的表单中返回所选的 id 值。
在我的情况下,每个按钮都会打开一个带有表单的模式。 但我无法返回表单中的 id...
function getId(myId)
{
document.getElementById("recupTitle").textContent = myId.id;
}
<ul>
<li><button id="1" onclick="getId(this);">Click the button 1</button></li>
<li><button id="2" onclick="getId(this);">Click the button 2</button></li>
<li><button id="3" onclick="getId(this);">Click the button 3</button></li>
<li><button id="4" onclick="getId(this);">Click the button 4</button></li>
<li><button id="5" onclick="getId(this);">Click the button 5</button></li>
</ul>
<p id="recupTitle"></p>
最佳答案
单击时还可以使用 id 设置表单值
document.getElementById("myField").value = myId.id;
关于javascript - 在联系表单 7 中显示 ID 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42528187/