18910140161

JavaScript-从表单获取.innnerHTML和警报文本-堆栈溢出

顺晟科技

2022-10-18 14:15:36

175

我正在尝试创建可以提交两个答案的表单。

在表单旁边,我想创建一个警报,当其中一个按钮被点击时,警报从表单中获取输入。很好用.

在表单旁边,我想创建另一个按钮,以HTML格式显示表单中的文本。

<代码>函数HtmlText(参数){document.getElementById(“ fName ”).innerHTML=alertText();document.getElementById(“ lname ”).innerHTML=alertText();}函数AlertText(参数){return “你的名字是:”+document.getElementById(“ fName ”).value+“ ”+document.getElementById(“ lname ”).value+“.”;}
<代码><;表单>;<;标签>;名称:<;/标签>;<;输入type=“ text ” ID=“ fname ”>;<;BR>;<;标签>;名称2:<;/标签>;<;输入type=“ text ” ID=“ lname ”>;<;BR>;<;/窗体>;<;button onclick=“ htmltext()”>;HTML<;/button>;<;button onclick=“ window.alert(alertText())”>;alert<;/button>;


顺晟科技:

你可能是故意这么做的。

请注意使用推荐的EventListener而不是内联事件处理程序

function htmlText(argument) {
  document.getElementById("fname").innerHTML = alertText();
  document.getElementById("lname").innerHTML = alertText();
}

function alertText(argument) {
  return "Your name is: " +
    document.getElementById("fname").value + " " +
    document.getElementById("lname").value + ".";
}
<代码><;表单>;<;标签>;名称:<;/标签>;<;输入type=“ text ” ID=“ fname ”>;<;BR>;<;标签>;名称2:<;/标签>;<;输入type=“ text ” ID=“ lname ”>;<;BR>;<;/窗体>;<;button type=“ button ” ID=“ htmlbutton ”>;HTML<;/button>;<;button type=“ button ” ID=“ AlertButton ”>;警报<;/button>;<;Sid ID=“ fullname ”>;<;/DIV>;

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航