把网页中的多个li的内容显示到canavas的方法
<body>
<ul style="display:none">
<li>this is the first line</li>
<li>this is the second line</li>
<li>this is the third line</li>
</ul>
<canvas id="canvas" width="600" height="300" style="background:pink;"></canvas>
<script>
function draw() {
var ctx = document.getElementById("canvas").getContext("2d");
ctx.font = "20px Times New Roman";
ctx.fillStyle = "black";
var li = document.getElementsByTagName("li")
var liLength = li.length;
var lineHeight = 25;
for (var i = 0; i < liLength; i++) {
ctx.fillText(li[i].innerHTML, 10, lineHeight);
lineHeight += 25;
}
}
draw()
</script>
</body>
(adsbygoogle = window.adsbygoogle || []).push({});
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有