It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
现在我有3个元素。顶部是文本框和提交按钮,下面是画布。单击提交按钮后,我想在画布上显示用户的输入。

我很高兴看到任何JavaScript建议

最佳答案

仅因为我非常喜欢使用画布..这应该可以帮助您入门。为了将来参考,请确保在提出问题时张贴您尝试过的内容,通常人们不喜欢为模糊的问题提供完整的解决方案。

var btn = document.getElementsByTagName("input")[0],
    textArea = document.getElementsByTagName("textarea")[0],
    canvas = document.getElementById("canvas"),
    ctx = canvas.getContext("2d");
    canvas.width = 512;

    ctx.font = "12px Arial";
    ctx.fillStyle = "#000";

    btn.addEventListener("click", function(){
        ctx.fillText(textArea.value,10,10);
    });
​


Live Demo

关于javascript - 在 Canvas 上显示用户的文字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13089071/

10-12 04:28