Uncaught ReferenceError: canvasLock is not defined
(function () {
window.canvasLock = function (obj) {
this.height = obj.height
this.width = obj.width
}
canvasLock.prototype.initDom = function () {
var wrap = document.createElement('div')
var str = '<h4 id="title" class="title">绘制解锁图案</h4>'
wrap.setAttribute('style', 'position:absolute;top:0;right:0;bottom:0;left:0')
var canvas = document.createElement('canvas')
canvas.setAttribute('id', 'canvas')
canvas.style.cssText = 'background-color:#305066;display:inlink-block;margin-top:15px'
wrap.innerHTML = str
wrap.appendChild(canvas)
var width = this.width || 300
var height = this.height || 300
document.body.appendChild(wrap)
// 高清屏缩放
canvas.style.width = width + 'px'
canvas.style.height = height + 'px'
}
// 程序初始化
canvasLock.prototype.init = function () {
this.initDom()
}
})()
----------------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>手势解锁</title>
<style>
body {
background: #305066;
text-align: center;
}
h4 {
color: #22C3AA;
}
</style>
</head>
<body>
<script src="./src/index.js"></script>
<script>
// 1 生成背景
// 2 动态title生成
// 3 用js动态生成canvas标签
// 4 js方式动态生成h3标签和canvas标签
new canvasLock({}).init()
</script>
</body>
</html>
正在回答
同学你好,使用同学提供的代码测试,控制台没有报错,如下:

可能是js文件引入的问题,按照同学的引入路径,index和src文件夹应该在同一目录下,js文件应该在src文件夹下,如下图

同学可以排查下目录结构是不是有问题,如果排查不出来,可以把自己的目录截图上来,老师帮助排查,祝学习愉快~
- 参与学习 人
- 提交作业 622 份
- 解答问题 6815 个
微信带火了小程序,也让前端工程师有了更多的展现机会,本阶段带你从移动基础知识的学习到webAPP开发,及小程序开发,让你PC端与移动端两端通吃。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星