开发者

HTML and javascript variables

开发者 https://www.devze.com 2023-04-13 01:58 出处:网络
How do you put a javascript variable into the value=\"\" of an <input> box on a <form> This must be easy but I do not开发者_JS百科 know.That\'s not hard. Have a look at the example below:

How do you put a javascript variable into the value="" of an <input> box on a <form>

This must be easy but I do not开发者_JS百科 know.


That's not hard. Have a look at the example below:

HTML:

<input id="id_of_your_element">

Javascript:

var yourvariable = "Hello world!";
document.getElementById("id_of_your_element").value = yourvariable;


document.getElementById('element-id').value = 'The Value';


Value="<script type="text/javascript">document.write(yourVariableName);</script>"


You can do just:

document.getElementById('inputId').value = yourVariable;

You can also use the jQuery library, it will:

$('#inputId').val(yourVariable);
  • jQuery : http://jquery.com/
  • function .val: http://api.jquery.com/val/
0

精彩评论

暂无评论...
验证码 换一张
取 消