假设我有如下表格。如何将名为“configname”的文本框中的值传递给 onclick 函数处理程序??
<form id="loadconfigform">
Config Name: <input type="text" name="configname" />
<input type="button" value="Submit" onclick="onLoadConfigPress(configname)" />
</form>
最佳答案
给输入字段一个id
:
<input type="text" id="configname" name="configname" />
现在修改点击处理程序如下:
<input type="button" value="Submit"
onclick="onLoadConfigPress(document.getElementById('configname').value)" />
或者,如果您在该页面上只有一个表单,您也可以使用 forms
数组:
<input type="button" value="Submit"
onclick="onLoadConfigPress(document.forms[0].configname.value)" />
关于javascript 将文本输入传递给 onclick 处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7427041/