我有这样的模板代码:
<img id ="canvas" src="../images/carsimage.jpg" />
我试图通过在 javascript 中创建类似 getElementById 的东西将此元素传递给函数。但是我收到“this.$.canvas”的错误
initDraw(this.$.canvas);
initDraw(canvas) {
}
最佳答案
你应该定义一个更好的问题并提供一个代码笔/ fiddle /任何东西,但是假设你想从一个组件调用它,你忘记了使用 this
调用 initDraw 函数。在 Polymer v2 中会是这样的:
ready() {
super.ready();
this.initDraw(this.$.canvas); //here call this.functionName
}
initDraw(canvas) {
console.log('canvas = ', canvas);
}
关于javascript - 如何将 getElementById(#canvas) 作为参数传递给 polymer 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46941807/