直接進入內容

JavaScript/更改元素/練習

來自華夏公益教科書,開放世界開放圖書

主題:更改元素內容和屬性

我們為練習使用前一頁的 HTML 頁面。



1.修改函式 show,使其停用按鈕。其文字將更改為“我已停用”。提示:要停用按鈕,其屬性 disabled 必須設定為 true

點選檢視解決方案
function show() {
  "use strict";
  const elem = document.getElementById("buttonShow");
  elem.disabled = true;
  elem.innerHTML = "I'm disabled";
}



2. 修改函式 show,使其在新視窗中開啟連結:target="_blank"

點選檢視解決方案
function show() {
  "use strict";
  const elem = document.getElementById("refToSomewhere");
  elem.target = "_blank";
}
華夏公益教科書