javascript - 文档.log() : "undefined is not a function"

标签 javascript

我知道,我知道,这是一个常见的错误,你应该看看别人,等等等等。我找到了,但我找不到解决方案。

这是我的完整代码。

<div id="div"></div>

<script>
function item(id, price, name, icon){
    this.id = id;
    this.initPrice = 0;
    this.price = price;
    this.name = name;
    this.icon = icon;

    document.getElementById("div").innerHTML += this.name + " = $" + price + " <input id=\"itemNum" + this.id + "\" onchange=\"item" + this.id + ".calc()\" type=\"number\" style=\"width: 40px;\" value=\"1\"></input><br>";

    this.calc = function(){
        document.log("yay");
    }
}

var item1 = new item(1, 700, "Barrel #1", "");
item1.calc();
</script>

我在第 14 行收到错误,当我更改输入时,我在第 14 行再次收到相同的错误。我究竟做错了什么?我该如何解决这个问题?

最佳答案

你需要使用:

console.log("yay");

代替:

document.log("yay");

Fiddle Demo

关于javascript - 文档.log() : "undefined is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23378214/

相关文章:

javascript - 从 chrome.storage 顺序检索多个项目

javascript - 如何使用 iron-ajax 将项目从 polymer 1 更新到 polymer 3

Javascript - 在两个日期对象之间创建数组

javascript - 如何测试带有回调函数的组件

javascript - 无法为 Firebase 部署 Cloud Functions

javascript - 省略对象项

javascript - 理解链构造函数中的 Function.prototype.apply 方法

javascript - 使用 Opera 小部件模拟器的 Opera 小部件中的文件 I/O 问题

javascript - 警报上的文字

javascript - 从 webpack.config.js 禁用 babel 严格模式