【问题标题】:Displaying Variables in Text Boxes in JavaScript在 JavaScript 的文本框中显示变量
【发布时间】:2015-02-24 07:49:30
【问题描述】:

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

在文档中:script.js

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

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

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

这是怎么做到的?

【问题讨论】:

标签: javascript html object textbox html-input


【解决方案1】:

在你定义shortsF.stockLevel之后放这个

document.querySelector('#textBox1').value = shortsF.stockLevel;

【讨论】:

    猜你喜欢
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    相关资源
    最近更新 更多