将javascript变量传递给html文本框 [英] Passing javascript variable to html textbox

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

问题描述



我得到一个javascript变量,并且我试图将该变量传递给html表单texbox。我想动态地在文本框中显示变量。但我不知道如何将变量传递给html表单并调用变量?

  var test; 

< INPUT TYPE =TEXTNAME =lgVALUE =SIZE =25MAXLENGTH =50disabled =disabled>< BR>< BR>

如何将测试传递给html表单并更改其值?



谢谢

解决方案

将变量传递给表单元素像这样



您的表单元素

 < input type =textid =mytext> 

javascript

  var test =Hello; 
document.getElementById(mytext)。value = test; //现在你在表单元素中获得了js变量


i need help on html form.

I got a javascript variable, and I am trying to pass the variable to a html form texbox. I want to display the variable on the textbox dynamically. but i do not know how to pass the variable to the html form and call the variable?

var test;

<INPUT TYPE="TEXT" NAME="lg" VALUE="" SIZE="25" MAXLENGTH="50" disabled="disabled"><BR><BR>

How do i pass test to html form and change its value?

Thanks

解决方案

Pass the variable to the form element like this

your form element

<input type="text" id="mytext">

javascript

var test = "Hello";
document.getElementById("mytext").value = test;//Now you get the js variable inside your form element

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

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