美好的一天,我使用 DOM 创建按钮,并在 JavaScript 中单击时切换以更改 HTML 文件中的段落,但是,这些按钮没有出现在 html 中,我已经将其设置为位于段落。我使用 CSS 来设置按钮的样式。以下是 JC、HTML 和 CSS 文件:
HTML:
<!DOCTYPE html>
<head>
<link scr="stylesheet" type="text/css" href="A3 .css">
<script src="A3.js"></script>
</head>
<div id ="button_containter"></div>
<body id= target_p>
In considering any new subject, there is frequently a tendency, first, to overrate what we find to be already interesting
or remarkable; and, secondly, by a sort of natural reaction, to undervalue the blue state of the case, when we do
discover that our notions have surpassed those that were really tenable
</body>
</html>
JS:
let para = document.getElementById("target_p");
class ParagraphChanger {
constructor (p){
this.p=p;
var btnDiv = document.getElementById("button_containter");
let btnBold = this.createButton("toggle bold");
btnBold.addEventListener('click',() => this.makeBold());
btnDiv.appendChild(btnBold);
let widthBtn = this.createButton("toggle width");
widthBtn.addEventListener('click', () => this.changedWidth());
btnDiv.appendChild(widthBtn);
let clrBtn = this.createButton("togglt color");
clrBtn.addEventListener('click', () => this.changeColor());
clrBtn.appendChild(clrBtn);
let szBtn = this.createButton("toggle size");
szBtn.addEventListener('click', () => this.changeSize());
}
createButton (name){
const btn = document.createElement('button_container');
const buttonName = document.createTextNode(name);
buttonName.appendChild(buttonName);
return btn;
}
makeBold(){
// changing the size to bold, getting it from CSS s
this.p.classList.toggle("Toggle_bold");
}
changedWidth(){
this.p.classList.toggle('Toggle_width');
}
changeColor(){
this.p.classList.toggle('Toggle_width');
}
changeSize(){
this.p.classList.toggle('Toggle_size');
}
拉丁的传说
翻翻过去那场雪