Javascript 将按钮附加到元素并更改其属性

Javascript 将按钮附加到元素并更改其属性,javascript,dom,button,event-handling,Javascript,Dom,Button,Event Handling,嘿,伙计们,我正在为我的个人项目制作一个小电子邮件应用程序,当我使用Javascript将一个按钮元素附加到一个div上时,我遇到了一个问题 显然,按钮正在显示,但几乎看不见 所以我试着把它的值改为“存档”,但它只剩下一个我几乎看不见的小按钮 如何使用javascript更改按钮的值 谢谢!下面是我的代码: fetch('/emails/' + id) .then(response => response.json()) .then(email => { d

嘿,伙计们,我正在为我的个人项目制作一个小电子邮件应用程序,当我使用Javascript将一个按钮元素附加到一个div上时,我遇到了一个问题

显然,按钮正在显示,但几乎看不见

所以我试着把它的值改为“存档”,但它只剩下一个我几乎看不见的小按钮

如何使用javascript更改按钮的值

谢谢!下面是我的代码:

fetch('/emails/' + id)
  .then(response => response.json())
  .then(email => {
    
    document.getElementById("message-view").innerHTML = "From: " + email.sender + "<p>To: " + email.recipients + "</p>" + "<p>Sent at: " + email.timestamp + "<p>Subject: " + email.subject + "</p>" + "<p>" + email.body + "</p>";
    const archiveButton = element.appendChild(document.createElement('button'));
    archiveButton.value = "Archive";
  });
fetch('/emails/'+id)
.then(response=>response.json())
。然后(电子邮件=>{
document.getElementById(“邮件视图”).innerHTML=“从:”+email.sender+“到:“+email.recipients+”

”+“+”发送到:“+email.timestamp+”主题:“+email.Subject+”

”+“+email.body+”

”; const archiveButton=element.appendChild(document.createElement('button'); archiveButton.value=“存档”; });
属性的
值不设置按钮内容。改为使用
textContent
属性:
archiveButton.textContent=“Archive”
属性
值不设置按钮内容。改为使用
textContent
属性:
archiveButton.textContent=“Archive”
值属性与输入标记一起使用

例如:

<input type="button" value="Click Me">
const button = document.querySelector("button")
button.textContent = "Archive"

值属性与输入标记一起使用

例如:

<input type="button" value="Click Me">
const button = document.querySelector("button")
button.textContent = "Archive"

检查CSS中的
按钮
。检查CSS中的
按钮