按钮单击后如何将Javascript函数值传递给文本框? [英] How Do I Pass Javascript Function Value To Textbox After Button Click?

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

问题描述

这是我的HTML代码



here is my html codes

<input type="text" name="textBox" id="textBox"/>

<a input type="button" class="btn" id="btnSeven" >Generate Birthday</a>







这是我的javascript函数






this is my javascript function

<script>
        function myFunction()
        {
        alert("Page is loaded");
        }







document.getElementById('btnSeven').onclick =  myFunction(){
 document.getElementById('textBox').value = document.getElementById('btnSeven').value;





});



< / script>



现在我想在单击按钮后将函数值传递给文本框。



});

</script>

now i want to pass function value to text box after i clicked the button.

推荐答案

使用jQuery可以非常轻松地实现这一点。



为此,您必须将jQuery文件包含在您想要使用它的页面中。

对我来说,jquery文件位于项目本身。

You can achieve this one very easily using jQuery.

For this you have to include the jQuery file to your page where you want to make use of it.
For me the jquery file is at root of the project itself.
<script src="jquery-2.0.3.js"></script>





以下是根据您的代码说明的示例: -



页面上说我们有两个元素,比如

1.按钮



Here is an example as per your code description :-

In page let say we have two elements like
1. Button

<input type="button" class="btn" id="btnSeven" value="Generate Birthday" />





2. TextBox



2. TextBox

<input type="text" name="textBox" id="textBox" /> 





然后通过调用方法设置单击按钮时的文本框值返回值: -





Then to set the textbox value on click of button by calling the method which returns the value :-


function (){


#btnSeven )。on( 点击功能(){
("#btnSeven").on("click", function () {


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

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