如何在html标签内使用javascript变量 [英] how to use a javascript variable inside html tag
本文介绍了如何在html标签内使用javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在HTML标记内使用JavaScript变量,请考虑以下示例。
How to use a JavaScript variable inside HTML tag , consider the following example.
<script> var tbIndx = 10 ;/script>
.
.
.
<input type="text" name="someInput" value="?">
我想要属性'value'
具有变量 tbIndx
的值而不是'?',那么如何?
我试过 $ {tbIndx}
和& {tbIndx};
但两者都不起作用。
请帮助
I want the attribute 'value'
to have the value of the variable tbIndx
instead of '?', so how to?
I tried ${tbIndx}
and &{tbIndx};
but both didn't work.
Please help
推荐答案
{tbIndx} 和& {tbIndx};
但两者都不起作用。
请帮助
{tbIndx} and&{tbIndx};
but both didn't work.
Please help
试试这个:
html中的
Try this:
in html
<input type="text" id="someInput" name="someInput"></input>
和javascript
and in javascript
var tbIndx = 10;
document.getElementById("someInput").value = tbIndx;
希望它有所帮助:)
hope it helps :)
这篇关于如何在html标签内使用javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文