这有什么问题?我得到一个imText没有定义的错误。我做了一些搜索,发现它与范围有关?有没有更好的方法来实现我想要做的事情,因为它也出现使用onClick事件也不建议。JS函数未定义(ReferenceError)
<script>
function imText(text) {
var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
ctx.font="20px Georgia";
ctx.fillStyle="white";
ctx.fillText(text, 10, 50);
{
</script>
<div class="canvas"></div>
<canvas id="area"></canvas>
<form action="text">
<h2>Enter Text:</h2>
<input type="text" id="getText" name="text" value="bee"/><br>
<input type="button" value="Submit" onclick="imText(document.getElementById('getText').value)" />
</form>
脚本中的最后一个字符('{')应该是'}' – Iso
您似乎没有关闭您的'imText'函数。它看起来像一个简单的错字,用'}替换最后一个'''' – NewToJS