javascript将文本输入传递给onclick处理程序 [英] javascript passing text input to a onclick handler
本文介绍了javascript将文本输入传递给onclick处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< form id = loadconfigform>
配置名称:< input type =textname =configname/>
< input type =buttonvalue =Submitonclick =onLoadConfigPress(configname)/>
< / form>
解决方案
给 id
输入字段:
< input type =textid =confignamename =configigname />
现在修改点击处理程序,如下所示:
< input type =buttonvalue =Submit
onclick =onLoadConfigPress(document.getElementById('configname')。value)/>
或者,如果您在该页面上只有一个表单,您还可以使用表单
数组:
< input type =buttonvalue =Submit
onclick =onLoadConfigPress(document.forms [0] .configname.value)/>
Lets say I have a form as below. How do I pass the value in the textbox named "configname" to the onclick function handler??
<form id="loadconfigform">
Config Name: <input type="text" name="configname" />
<input type="button" value="Submit" onclick="onLoadConfigPress(configname)" />
</form>
解决方案
Give an id
to input field:
<input type="text" id="configname" name="configname" />
Now modify click handler as follows:
<input type="button" value="Submit"
onclick="onLoadConfigPress(document.getElementById('configname').value)" />
Or if you have only one form on that page, you could also use forms
array:
<input type="button" value="Submit"
onclick="onLoadConfigPress(document.forms[0].configname.value)" />
这篇关于javascript将文本输入传递给onclick处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文