如何使用事件监听器将标题和页脚文本更改为输入到文本框中的提示

huangapple go评论67阅读模式
英文:

How do I use event listeners to change the title and footer text to a prompt entered into a text box

问题

我试图将页眉和页脚文本更改为文本框中输入的任何内容。代码不能使用document.write()

我的当前脚本代码如下:

var headerchange = document.createTextNode(headerText);
h.appendChild(headerchange);

function header() {
    document.getElementById("Text").innerHTML = headerText;
}

document.addEventListener("input", footer);

function footer() {
    document.getElementById("Text").innerHTML = footText;
}

function enter() {
    document.getElementById("done").element.click();
}
英文:

I'm trying to change the header and footer text from what its currently saying to whatever is entered into a text box. Code cannot be document.write()

my current script code is listed below

var headerchange = document.createTextNode(headerText);
h.appendchild(headerchange);



function header() {
    document.getElementById("Text").innerHTML = headerText;
}

document.addeventListener("input", footer);

function footer() {
    	document.getElementById("Text").innerHTML = footText;
}


function enter() {
    document.getElementById("done")element.click();
}

答案1

得分: 0

以下是您要翻译的代码部分:

为什么你在这里将id用作文本 `input type=text id=headerText  /label  br`因为你在这里将id用作headerText

const headerTextBox = document.getElementById("headerText");
const footerTextBox = document.getElementById("footerText");

headerTextBox.addEventListener("input", updateHeader);
footerTextBox.addEventListener("input", updateFooter);

function updateHeader() {
  const headerText = headerTextBox.value;
  const newHeaderText = document.createTextNode(headerText);
  const headerElement = document.querySelector("h1");
  headerElement.innerHTML = "";
  headerElement.appendChild(newHeaderText);
}

function updateFooter() {
  const footerText = footerTextBox.value;
  const newFooterText = document.createTextNode(footerText);
  const footerElement = document.querySelector("h2");
  footerElement.innerHTML = "";
  footerElement.appendChild(newFooterText);
}

请注意,我已经去掉了HTML标签中的HTML实体编码(例如," 被翻译为双引号)。

英文:

why are you using id as text input type=text id=headerText /label br as here you are using id as headerText

const headerTextBox = document.getElementById("headerText");
const footerTextBox = document.getElementById("footerText");

headerTextBox.addEventListener("input", updateHeader);
footerTextBox.addEventListener("input", updateFooter);

function updateHeader() {
  const headerText = headerTextBox.value;
  const newHeaderText = document.createTextNode(headerText);
  const headerElement = document.querySelector("h1");
  headerElement.innerHTML = "";
  headerElement.appendChild(newHeaderText);
}

function updateFooter() {
  const footerText = footerTextBox.value;
  const newFooterText = document.createTextNode(footerText);
  const footerElement = document.querySelector("h2");
  footerElement.innerHTML = "";
  footerElement.appendChild(newFooterText);
}

huangapple
  • 本文由 发表于 2023年5月10日 11:20:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76214670.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定