javascript将文本输入传递给onclick处理程序 [英] javascript passing text input to a onclick handler

查看:125
本文介绍了javascript将文本输入传递给onclick处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有一个表格,如下所示。如何将名为configname的文本框中的值传递给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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆