我在页面上有一些非常简单的表单,全部结构如下。我只需要在按下链接时提交带有值的表单。有没有一种方法可以在单击的表单中提交值,而不必唯一地标识每个表单?
<form action="result.php" method="post">
<input name="id" type="hidden" value="10" />
<a href="#" onclick="document.getElementByName('id').submit();">
some text with styling to click
</a>
</form>
最佳答案
尝试在 this.parentElement
上调用 .submit()
<form action="result.php" method="post">
<input name="id" type="hidden" value="10" />
<a href="#" onclick="this.parentElement.submit();">
some text with styling to click
</a>
</form>
关于javascript - 提交表单值的非常简单的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35116157/