Wie verwende ich Stil in JavaScript ohne CSS?
Pavel
Wie verwende ich Stil in JavaScript ohne CSS? Ich versuche, Formen zu zeichnen, aber es gibt ein Problem mit dem Stil ... Bitte helfen Sie.
Etwas läuft falsch
var Shape = function (width, height, radius) {
this.width = width;
this.height = height;
this.radius = radius;
this.drawShape = function () {
var shape = document.createElement("div");
document.body.appendChild(shape);
shape.style.width = this.width;
shape.style.height = this.height;
shape.style.radius = this.radius;
shape.style.border = '1px solid black'
}
}
var shape1 = new Shape(10, 30, 30);
shape1.drawShape();
Nenad Vracar
Sie müssen Einheiten einstellen, auch anstelle von radius
sollten Sie verwenden borderRadius
.
var Shape = function(width, height, radius) {
this.width = width;
this.height = height;
this.radius = radius;
this.drawShape = function() {
var shape = document.createElement("div");
document.body.appendChild(shape);
shape.style.width = this.width + 'px';
shape.style.height = this.height + 'px';
shape.style.borderRadius = this.radius + 'px';
shape.style.border = '1px solid black'
}
}
var shape1 = new Shape(10, 30, 30);
shape1.drawShape();