【发布时间】:2016-02-22 20:38:05
【问题描述】:
我想创建一个小网站,以便在图像上添加文字。我添加了一个文本框和一个按钮来插入自定义文本,但它不起作用。我究竟做错了什么?提前致谢
<script>
function = function1(){
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var imageObj = new Image();
t = document.getElementById('text').value;
if(t == '' || t == null) {
word = "you forgot to put something";
} else {
word = t;
}
};
imageObj.onload = function(){
context.drawImage(imageObj, 10, 10);
context.font = "40pt Calibri";
context.fillText(word, 20, 20);
};
imageObj.src = "img/image.jpg";
};
</script>
<body>
<canvas id="myCanvas" width="578" height="400"></canvas>
</body>
<form>
Text: <input id="textBox" placeholder="your text"/>
<br>
<input type='submit' id="submit" value="submit" onClick="function1()" >
</form>
【问题讨论】:
-
“它不起作用” 什么不起作用?
-
我看不到图片和文字...
标签: javascript html canvas text