在JavaScript中显示文本框中的变量

时间:2014-12-27 11:02:51

标签: javascript html object textbox html-input

我正在尝试使文本框显示对象属性的值。我希望文本框显示项目的当前库存水平,例如:

在文档中: script.js

var shortsF = new Object ( );
shortsF.description = "Stone Wash Denim Shorts";
shortsF.stockLevel = 20;
shortsF.price = 25.9

我希望index.html上的文本框“textBox1”将shortsF.stockLevel显示为其默认值。 e.g。

<input type="text" id="textBox1" readOnly="true" value=??? />

这是怎么做到的?

1 个答案:

答案 0 :(得分:-1)

在定义shortsF.stockLevel

后放置此内容
document.querySelector('#textBox1').value = shortsF.stockLevel;