JavaScript面向对象存储多个项目和属性并显示
你能帮我吗,我一直在使用一本书,他们向我展示了一种用JavaScript创建对象的方法,我使用了这种方法,但我在显示它时遇到了问题。我的目标是使用HTML5将其显示在一个表中,我将再创建9个要调用和显示的项。这本书告诉我使用product1.ShowDetails来显示它,但我尝试过,但遇到了问题 谢谢你抽出时间 詹姆斯JavaScript面向对象存储多个项目和属性并显示,javascript,html,Javascript,Html,你能帮我吗,我一直在使用一本书,他们向我展示了一种用JavaScript创建对象的方法,我使用了这种方法,但我在显示它时遇到了问题。我的目标是使用HTML5将其显示在一个表中,我将再创建9个要调用和显示的项。这本书告诉我使用product1.ShowDetails来显示它,但我尝试过,但遇到了问题 谢谢你抽出时间 詹姆斯 JavaScript属性区分大小写。在构造函数中,您将this.Product设置为Product参数,但showDetails函数引用this.Product参数 另外,您的
JavaScript属性区分大小写。在构造函数中,您将this.Product设置为Product参数,但showDetails函数引用this.Product参数 另外,您的代码似乎有输入错误,最后一个括号不应该在product1声明之前吗
<script>
function Item(product, description, stockLevel, price)
{
this.Product = product
this.Description = description
this.Stock_Level = stockLevel
this.Price = price
this.showHeading = function()
{
document.write(this.product )
document.write(this.description)
document.write(this.stockLevel)
document.write(this.price)
}
this.showDetails = function()
{
document.write(this.product)
document.write(this.description)
document.write(this.stockLevel)
document.write(this.price)
}
product1 = new Item("Shorts (F)", "Stone Wash Dmin Shorts", 20, 25.90);
}