如何将html文本框值传递给javascript函数 [英] How to pass html textbox value to a javascript function

查看:73
本文介绍了如何将html文本框值传递给javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML文本框,用户可以在其中输入一些要传递给JavaScript函数的字符串:

I have a HTML textbox where user will input some string which i want to pass to a JavaScript function:

<input type="text" id="ad_search_query" style="width:295px">&nbsp;
<input type="button" value="<s:text name="button.search"/>" class="p-userButton"
 onClick="ADSEARCHGF.showTable('');"/> 

请提出我该怎么做.

推荐答案

如果按钮引发了该事件,则没有先输入该对象的文本输入对象就不会传递给该函数,通过id获得它是最好的方法.

If the event is raised by the button, you will not have the text input object to pass to the function without getting it first, getting it by id is the best way.

您可以使用文本框的ID:

You can use the id of the text box:

var searchValue = document.getElementById('ad_search_query').value;

在您的函数中,或使用Ahsan Rathod的方法将此代码用作参数.

in your function, or use Ahsan Rathod's method to use this code as parameter.

这篇关于如何将html文本框值传递给javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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