我是JS编程的初学者。我有一个CanvasObjet类,该类是有效的(我在HTML上对其进行了测试),当我单击某些按钮时,我希望此画布出现在弹出窗口中。我尝试了window.open(),但它并不是我想要的,而alert()在[HTMLCanvasElement]中返回了我的画布。

class Formulaire {
constructor() {
reserv.addEventListener("click", ()=>{
//the function i need for a popup of canvas here
localStorage.setItem("nom",nom.value);
localStorage.setItem("prenom",prenom.value);
this.tempsRestant();
temps.textContent = "Lorem Ipsum" + prenom.value + "Lorem Ipsum " + nom.value;
})

class CanvasObjet {
constructor() {
this.canvas = document.getElementById('canvas');
//Appelle l'interface CanvasRenderingContext2d
this.ctx = this.canvas.getContext('2d');
this.ctx.strokeStyle = '#000000';
this.ctx.lineWidth = 3;
this.draw = false;
this.mousePosition = {
    x: 0,
    y: 0
    };
this.lastPosition = this.mousePosition;
this.clearButton = document.getElementById("clear");
this.canvas.width = 300;
this.canvas.height = 300;
this.evenements();
};


<canvas id="canvas" width="300" height="300"></canvas>

最佳答案

Window.open在新选项卡中打开内容。

如果您想要弹出窗口,则需要使用CSS进行此操作。但是我建议您为此使用引导程序,我一直都在使用它。

查看模态(弹出窗口)的文档:https://getbootstrap.com/docs/4.3/components/modal/

希望对您有所帮助。

08-04 17:28