简体   繁体   English

制作可编辑的标题文本将不起作用!

[英]Making editable header text, won't work!

I have a header message that is brought in from another file (message.txt), and I'm making a text box that you can edit. 我有从另一个文件(message.txt)引入的标头消息,并且正在制作一个可以编辑的文本框。 (I will add the part where it makes it permanent later on.) It is changing to nothing. (稍后将添加使它永久化的部分。)它什么都没有改变。

(E: "This is the header!" to "") (E:“这是标题!”到“”)

This is the code.. 这是代码。

<script type="text/javascript">
function change(text)
{
//document.forms["f1"].elements["ta"].value="Hi!";
//document.f1.ta.value="Hi!";
document.getElementById("msg").innerHTML='<h2 class="hmsg">'+text+'</h2>';
}
function getText()
{
return document.getElementById("ta").value;
}
function all()
{
change(getText())
}
</script>
<form name="f1">
<input type="text" value="Enter your message here!" id="ta"/>
<input type="button" value="          " onclick='all()'/>
</form>

Perhaps you can clarify what is not working as you expect. 也许您可以弄清什么不是您期望的。 I expanded your code into a working example: 我将您的代码扩展为一个有效的示例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Test</title>
</head>
<body>
<script type="text/javascript">
function change(text)
{
  document.getElementById("msg").innerHTML='<h2 class="hmsg">'+text+'</h2>';
}
function getText()
{
return document.getElementById("ta").value;
}
function all()
{
  change(getText())
}
</script>
<form action="#">
<div id="msg">
</div>
<div>
<input type="text" value="Enter your message here!" id="ta"/>
<input type="button" value="          " onclick='all()'/>
</div>
</form>
</body>
</html>

Changing the content of the <div> with id msg works here. 在此处更改ID为msg<div>的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM