I'我想放下画布上的文字.帮帮我
I'm want to drop text of canvas.. help me
尊敬的开发人员。
在写这个问题之前,我的英语很差。
我正在学习javascript。
但有一个问题是工作。。
我想放下画布上的文字。。但是我不知道如何放下这条短信。。
如何修改此代码。。?请帮帮我…
<script type="text/javascript">
var Text_array = new Array("exam1", "exam2", "exam3");
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
for (i = 0; i < 3; i++) {
ctx.fillText(Text_array[i], 100 * i + 10, 50);
}
function removeText()
{
var removeText = document.getElementById("txtWord").value;
var position = Text_array.indexOf(removeText);
if( position > -1)
{
Text_array.splice(position,1);
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (i = 0; i < Text_array.length; i++) {
ctx.fillText(Text_array[i], 100 * i + 10, 50);
}
}
}
</script>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
.box {
position: relative;
width: 800px;
height: 600px;
}
.box canvas {
border: 1px solid red;
}
.box .control {
position: relative;
bottom: 30px;
z-index: 999;
width: 100%;
padding: 5px;
border: 1px solid blue;
display: inline-block;
}
.box .control input {
float: left;
width: 45%;
}
.box .control button {
float: right;
width: 45%;
color: #000;
margin-right: 15px;
}
</style>
</head>
<body>
<div class="box">
<canvas id="myCanvas" width="800" height="600">
Your browser does not support the canvas element.
</canvas>
<div class="control">
<input id="txtWord" type="text" name="word" value="">
<button type="button" class="btn" title="" onclick="javascript:removeText();" >Btn</button>
</div>
</div>
</body>
</html>
这个代码一切都很好,只是我删除了<script type="text/javascript">
和</script>
表单代码,它的工作。。。
var Text_array = new Array("exam1", "exam2", "exam3");
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
for (i = 0; i < 3; i++) {
ctx.fillText(Text_array[i], 100 * i + 10, 50);
}
function removeText()
{
var removeText = document.getElementById("txtWord").value;
var position = Text_array.indexOf(removeText);
if( position > -1)
{
Text_array.splice(position,1);
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (i = 0; i < Text_array.length; i++) {
ctx.fillText(Text_array[i], 100 * i + 10, 50);
}
}
}
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
.box {
position: relative;
width: 800px;
height: 600px;
}
.box canvas {
border: 1px solid red;
}
.box .control {
position: relative;
bottom: 30px;
z-index: 999;
width: 100%;
padding: 5px;
border: 1px solid blue;
display: inline-block;
}
.box .control input {
float: left;
width: 45%;
}
.box .control button {
float: right;
width: 45%;
color: #000;
margin-right: 15px;
}
</style>
</head>
<body>
<div class="box">
<canvas id="myCanvas" width="800" height="600">
Your browser does not support the canvas element.
</canvas>
<div class="control">
<input id="txtWord" type="text" name="word" value="">
<button type="button" class="btn" title="" onclick="javascript:removeText();" >Btn</button>
</div>
</div>
</body>
</html>
相关文章:
- EaseJS拖放;放下(动画CC)电影剪辑的鼠标坐标
- 添加文字和评论功能更新Div
- 如何计算对象文字中的键
- I'我想放下画布上的文字.帮帮我
- 对象文字方法上的Javascript绑定不起作用
- 以ECMAScript 5及更高版本为目标时,八进制文字不可用
- ES6 模板文字是否比 eval 更安全
- 是索引数组文字的好做法
- 从多行文字中获取第一个修剪的字符串
- 如何在只接受字符串值/文字的HTML属性中调用函数
- 可以使用“;创建“;作为JavaScript对象文字中的属性名称
- 如何避免“;使用数组文字表示法“;以下javascript代码中的jslint错误
- 如何使用jQuery以文字显示现金价值
- 这两种不同的创建对象文字的方法有什么区别
- 如何将变量而不是文字数字放进去
- Javascript对象文字,POST问题
- 为什么可以对整数变量调用toString(),而不能对文字数字调用
- 为什么可以'我们在函数体中为函数对象添加属性,就像在javascript中为对象文字添加属性一样
- 如何使用'这个“;对象文字中的关键字
- RegEx将有理文字与小数匹配,但不完全有理文字除外