先上代码
<script type="text/javascript">
var but = document.getElementById("random");
var canvas = document.getElementById("canvas");
but.addEventListener('click', function(event) {
event.stopPropagation();
if (canvas != null) {
var context = canvas.getContext('2d');
context.fillStyle = '#FFFFFF';
context.font = 'bold 40px 微软雅黑';
var num = 123;
context.fillText(num,110,110);
}
});
</script>
然后是效果图