< TEXTAREA>是一件奇怪的事。 [英] A <TEXTAREA> is a weird thing.

查看:43
本文介绍了< TEXTAREA>是一件奇怪的事。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设计一个可以自行编辑的HTML页面。从本质上讲,它就像一个Wiki页面,但是我自己的非常简单的版本。这是一个完整的页面

普通的旧HTML内容,然后在底部,有一个编辑

链接。所以页面本身看起来像这样:


< HTML>< HEAD>< TITLE> blah< / TITLE>< / HEAD>< BODY>

<! - TEXT STARTS HERE - >


< H1> Hello World!< / H1>

< ; P>这里有更多东西...< / P>


<! - TEXT ENDS HERE - >

< A HREF =" /cgi-bin/editpage.cgi?page = thisfile.html">编辑< / A>

< / BODY>< / HTML>

因此,如果您点击编辑按钮链接,CGI脚本熄灭并读取thisfile.html的

主体。文件。它使用那些特殊的TEXT STARTS

HERE用于标识可编辑内容开始和停止位置的标记。它然后只需将这些标签之间的任何内容转储到一个看起来像这样的页面中:


< HTML>< ; HEAD>< TITLE> blah< / TITLE>< / HEAD>< BODY>

< FORM ACTION =" /cgi-bin/savepage.cgi" METHOD =POST>

< TEXTAREA NAME =" pagetext" COLS = QUOT; 120" ROWS = QUOT 35 QUOT; WRAP =" OFF">


< H1> Hello World!< / H1>

< P>这里有更多东西...... < / P>


< / TEXTAREA>

< INPUT TYPE = SUBMIT VALUE =" Save">

< / FORM>

< / BODY>< / HTML>


因此,在该页面上,您可以编辑任何您想要的内容TEXTAREA和

然后点击保存按钮。按钮和savepage.cgi按钮脚本会将新数据写入thisfile.html。到目前为止,这很有效。


但是当我开始尝试在TEXTAREA中输入特殊的

字符时,我遇到了麻烦。例如,我打开页面并单击

" Edit"链接,然后开始输入这样的花哨的东西:


< H1> Hello World!< / H1>

< P>这里有更多的东西...< / P>

& lt;& nbsp;& nbsp;一些文字& nbsp;& nbsp;& gt;


它起初似乎*起作用*。当我保存页面然后查看它时,

当然,我看到了我的期望,例如:


Hello World!

这里有更多东西......

<一些文字>


但是下次我尝试编辑它时,我可以看到某些东西已经消失了。

表面下可怕的错误。 & nbsp;字符已经消失了,

并且被一些奇怪的unicode空格字符所取代(或者是什么?b $ b b?)。 & lt;和& gt;被实际的<<"取代和>

符号,这一点都不好。网络浏览器现在认为

"< Some text>"是某种标签,并没有显示它。 Yuck。


所以我搜索了一下,我发现它< TEXTAREA>的行为实际上是标准的

行为。字段自动执行转换

这样。好的,好的,那么我该如何改变这个功能呢?关闭,以便

*正好*我输入的内容被保存了?起初,我认为我可以在我的CGI脚本中修改

,只需要始终展开<"和>和其他

特殊字符回到它们的HTML等价物中。


但是这显然不会起作用,因为它会破坏

整个文件。事实上,上面例子中的文字将变成:


& lt; H1& gt; Hello World!& lt; / H1& gt;

& lt; P& gt;这里有更多东西...& lt; / P& gt;

...


呃。所以我不能在剧本中解决这个问题。我需要关闭TEXTAREA的这个

哑行为,否则这是行不通的。我需要

"& lt;"保持& lt;我需要<保持<就是这样。任何

想法?


感谢您的阅读,感谢您的帮助。


Pat

解决方案

Les Paul写道:

我正在尝试设计一个可以编辑自己的HTML页面。从本质上讲,它就像一个Wiki页面,但我自己的非常简单的版本。这是一个完整的旧HTML内容的页面,然后在底部,有一个编辑链接。所以页面本身看起来像这样:

< HTML>< HEAD>< TITLE> blah< / TITLE>< / HEAD>< BODY>
<! - 文本在这里开始 - >

< H1> Hello World!< / H1>
< P>这里有更多的东西......< / P>

<! - TEXT ENDS HERE - >
< A HREF =" /cgi-bin/editpage.cgi?page = thisfile.html"> Edit< / A> ;
< / BODY>< / HTML>

因此,如果您点击编辑按钮链接,CGI脚本熄灭并读取thisfile.html的主体。文件。它使用那些特殊的TEXT STARTS
HERE。用于标识可编辑内容开始和停止位置的标记。然后将这些标签之间的任何内容转储到一个看起来像这样的页面:

< HTML>< HEAD>< TITLE> blah< / TITLE> < / HEAD>< BODY>
< FORM ACTION =" /cgi-bin/savepage.cgi" METHOD =POST>
< TEXTAREA NAME =" pagetext" COLS = QUOT; 120" ROWS = QUOT 35 QUOT; WRAP =" OFF">

< H1> Hello World!< / H1>
< P>这里有更多内容......< / P>

< / TEXTAREA>
< INPUT TYPE = SUBMIT VALUE =" Save">
< / FORM>
< / BODY>< / HTML> ;

因此,在该页面上,您可以在TEXTAREA中编辑任何您想要的内容,然后单击保存按钮。按钮和savepage.cgi按钮脚本会将
新数据写入thisfile.html。到目前为止,这很有效。

但是当我开始尝试在TEXTAREA中输入特殊的
字符时,我遇到了麻烦。例如,我打开页面并单击
编辑按钮。链接,然后开始键入这样的花哨的东西:

< H1> Hello World!< / H1>
< P>这里有更多东西......< / P>
& lt;& nbsp;& nbsp;一些文字& nbsp;& nbsp;& gt;

它*似乎*首先起作用。当我保存页面然后查看它时,确实,我看到了我的期望,例如:

Hello World!
这里有更多的东西......
<一些文字>

但是下次我尝试编辑它时,我可以看到表面下方出现了可怕的错误。 & nbsp;字符已经消失,
并被一些奇怪的unicode空格字符(或某些东西?)所取代。 & lt;和& gt;被实际的<<"取代和>
符号,这一点都不好。网络浏览器现在认为
< Some text>是某种标签,并没有显示它。 Yuck。

所以我搜索了一下,我发现它实际上是< TEXTAREA>的标准行为。字段自动执行转换
这样的。好的,好的,那么我该如何改变这个功能呢?关闭,以便
*确切*我输入的内容得到保存?起初,我认为我可以通过总是扩展<来在我的CGI脚本中修复它。和>和其他
特殊字符回到他们的HTML等价物。

但显然不会工作,因为它会破坏整个文件中的每个标签。事实上,上面例子中的文字将成为:

& lt; H1& gt; Hello World!& lt; / H1& gt;
& lt; P& GT;这里有更多的东西...& lt; / P& gt;
...

呃。所以我不能在剧本中解决这个问题。我需要关闭TEXTAREA的这种愚蠢的行为,否则这是行不通的。我需要
"& lt;"保持& lt;我需要<保持<就是这样。任何
想法?

感谢阅读,感谢您的帮助。




您必须至少逃避<和& (以及你想看到的任何其他角色

一个实体而不是''奇怪的unicode空白字符'',例如

字符,ASCII码160进入''& ;'')在插入HTML之前将

编辑到< textarea>在你的脚本中。在

中查找编程语言库中的适当函数。


生成的HTML代码应如下所示:

< TEXTAREA>

& lt; H1& gt; Hello World!& lt; / H1& gt;

& lt; P& ; GT;这里有更多东西......& lt; / P& gt;

& amp; lt;& amp; nbsp;& amp; nbsp;一些文字& amp; nbsp;& amp; nbsp;& amp; gt;

< / TEXTAREA>


浏览器不需要要知道可编辑文本是HTML代码。

浏览器解析的事实,例如< H1>作为文字字符串< H1>而不是

a< H1>标签(在< TEXTAREA>中是不允许的)只是另一种b $ b'过度宽容行为的情况,这显然只会导致混淆。


-

Benjamin Niemann

电子邮件:粉红色at odahoda dot de

WWW: http://www.odahoda.de/


Benjamin Niemann< pi * *@odahoda.de>写在


[cut]

你必须至少逃避<和& (和你想要看作实体的任何其他角色而不是''奇怪的unicode空格字符'',例如,在你之前将ASCII代码160的字符变成''& nbsp;'')
插入HTML以编辑到< textarea>在你的脚本中。在您的编程语言库中寻找适当的功能。

生成的HTML代码应如下所示:

< TEXTAREA>
& lt; H1& gt; Hello World!& lt; / H1& gt;
& lt; P& gt;此处有更多内容...& lt; / P& gt;
& amp; lt;& amp; nbsp;& amp; nbsp;一些文字& amp; nbsp;& amp; nbsp;& amp; gt;
< / TEXTAREA>

浏览器不需要知道可编辑文本是HTML代码。
浏览器解析的事实,例如< H1>作为文字字符串< H1>
而不是< H1>标签(在< TEXTAREA>中不允许)仅仅是过度宽容行为的另一种情况,显然只会导致混淆。



这正是我不希望发生的事情。我不想要< H1>将

转换为任何东西,我希望它保持为< H1>。同样,我不希望
想要& lt;转换为<。如果用户键入< H1> blah

< / H1>在框中,他希望得到一个页面上有一个大而大胆的等等

。如果他输入& lt;,然后他希望得到一个带有<的页面。在

它。我不希望TEXTAREA为我转换其中任何一个。我可以在我的脚本文件中进行任何类型的转换,但是它不会工作。


这就是我在谈论的内容我说:

起初,我认为我可以通过总是扩展<来修复我的CGI脚本中的内容。 ;和>和其他
特殊字符回到他们的HTML等价物。

但显然不会工作,因为它会破坏整个文件中的每个标签。




如果看一下我的例子,这里用户输入的内容是什么,

字母是完全没有字母的已被转换):


< H1> Hello World< / H1>

这里有更多东西......

& lt;& nbsp;& nbsp一些文字& nbsp;& nbsp;& gt;


然后他点击保存按钮表单上的按钮。但在它获得我的CGI脚本之前,它已经被破坏了。所以在我的perl代码中,这个

就是字符串对我来说的样子:


< H1> Hello World< / H1>

这里有更多的东西......

<一些文字>


看到问题?我怎么知道哪个<和>字符应该是

转换*返回*到HTML代码(例如& lt;)?这一点已经太晚了

。我无法知道是否<一些文字>是一个HTML标签

喜欢< H1>,或者如果用户真的想要一个小于号,

后跟三个空格,其次是通过一些文本等......


Pat


Les Paul写道:

Benjamin Niemann< pi * *@odahoda.de>写道

[cut]

你必须逃脱至少<和& (以及你想看到的任何其他角色作为一个实体,而不是''奇怪的unicode空白角色'',
......
生成的HTML代码应如下所示:

< TEXTAREA>
& lt; H1& gt; Hello World!& lt; / H1& gt;
& lt; P& gt;此处有更多内容.. 。& lt; / P& gt;
& amp; lt;& amp; nbsp;& amp; nbsp; some some& amp; nbsp;& amp; nbsp;& amp; amp; GT;
< / TEXTAREA>
这正是我不希望发生的事情。




然而,它是确切地说,如果这对你来说是正确的,那么你必然会发生这种情况。你只是误解了背后的原因。
我不想要< H1>转换为任何东西,我希望它保持为
< H1>。


是的,你希望< h1>成为< h1>最后的文件,但为了它

必须转换为编辑过程正确发生。


例如,如果这是非常最终文件是:* b $ b< h1> Heading< / h1>


当用户选择编辑页面时想要在textarea中显示标记

,供用户编辑和提交,这应该是这样的图:

______________________

|< h1>标题< / h1> |

| |

| _____________________ |


要正确完成的标记,需要这样:


< textarea rows =" ..." cols =" ...">

& lt; h1& gt; Heading& lt; / h1& gt;

< / textarea>


当前系统产生的标记...


< textarea rows =" ..." cols =" ...">

< h1> Heading< / h1>

< / textarea>


....无效,因为textarea的内容定义为#PCDATA,

不是#CDATA,所以元素和实体引用应该被解析

作为元素和实体引用,而不是纯文本,尽管现有标签 - 汤浏览器的行为是b $ b。尝试通过

验证器运行您当前的站点,您将看到我的意思。
http://validator.w3.org/

同样,我不想要& lt;转换为<<"。




然后,在textarea中,您的系统必须转换所有的&符号&"

到& amp ;.这意味着,任何地方都有实体参考,例如& amp;,

& lt;或& gt;发生时,输出必须是& amp; amp; amp; amp; lt;和

& amp; gt;分别。因此,任何正义和放大的发生和& lt;和

& gt;将始终由浏览器转换,但这将为您提供所需的

结果,并且是有效的标记。


因此,扩展前面的示例,文本区域标记可能看起来像这样(我已经添加了空格以便于阅读):


< textarea rows =" .. " cols =" ...">

& lt; h1& gt; Heading& lt; / h1& gt;


& LT; p&安培; GT; &放大器;放大器; LT;一些& amp; nbsp; Content& amp; gt; & lt; / p& gt;

< / textarea>


提交后,系统应转换所有& amp;,& LT; &安培; GT;返回

到&,<和>分别。因此,当提交上述内容时,最终的

输出标记应为:


< h1>标题< / h1>


< p> &安培; LT;一些& nbsp; Content& gt; < / p>


我希望这能为你解释清楚。


-

Lachlan寻找
http://lachy.id.au/
http://GetFirefox.com/ 重新发现网页
http://GetThunderbird.com/ 回收收件箱


I''m trying to design an HTML page that can edit itself. In essence, it''s
just like a Wiki page, but my own very simple version. It''s a page full
of plain old HTML content, and then at the bottom, there''s an "Edit"
link. So the page itself looks something like this:

<HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY>
<!-- TEXT STARTS HERE -->

<H1>Hello World!</H1>
<P>More stuff here...</P>

<!-- TEXT ENDS HERE -->
<A HREF="/cgi-bin/editpage.cgi?page=thisfile.html">Edit</A>
</BODY></HTML>

So if you click the "Edit" link, the CGI script goes out and reads the
body of the "thisfile.html" file. It uses those special "TEXT STARTS
HERE" tags to identify where the editable content starts and stops. It
then just dumps whatever is between those tags into a page that looks
like this:

<HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY>
<FORM ACTION="/cgi-bin/savepage.cgi" METHOD="POST">
<TEXTAREA NAME="pagetext" COLS="120" ROWS="35" WRAP="OFF">

<H1>Hello World!</H1>
<P>More stuff here...</P>

</TEXTAREA>
<INPUT TYPE=SUBMIT VALUE="Save">
</FORM>
</BODY></HTML>

So, on that page, you can edit whatever you want inside the TEXTAREA and
then click the "Save" button and the "savepage.cgi" script will write the
new data right into "thisfile.html". And so far, this works great.

But I ran into trouble as soon as I started trying to enter special
characters in the TEXTAREA. For example, I open the page and click the
"Edit" link and then start typing in fancy stuff like this:

<H1>Hello World!</H1>
<P>More stuff here...</P>
&lt;&nbsp;&nbsp; Some text &nbsp;&nbsp;&gt;

And it *seems* to work at first. When I save the page and then view it,
sure enough, I see what I''d expect, something like:

Hello World!
More stuff here...
< Some text >

But the next time I try to edit it, I can see that something has gone
horribly wrong underneath the surface. The "&nbsp;" characters are gone,
and have been replaced by some weird unicode whitespace characters (or
something?). The "&lt;" and "&gt;" get replaced by actual "<" and ">"
symbols, which is no good at all. The web browser now thinks that
"<Some text>" is some sort of tag and doesn''t display it at all. Yuck.

So I searched around a little, and I see that it''s actually standard
behavior for the <TEXTAREA> field to automatically perform conversions
like this. Ok, fine, so how do I turn this "feature" off so that
*exactly* what I type gets saved? At first, I thought that I could fix
it in my CGI script by just always expanding "<" and ">" and other
special characters back into their HTML equivalents.

But that obviously won''t work, because then it will mangle every tag in
the whole file. In fact, the text in the example above would become:

&lt;H1&gt;Hello World!&lt;/H1&gt;
&lt;P&gt;More stuff here...&lt;/P&gt;
...

Ugh. So I can''t really solve this in the script. I need to turn this
dumb behavior of the TEXTAREA off, or this just can''t work. I need for
"&lt;" to stay "&lt;" and I need for "<" to stay "<" and that''s it. Any
ideas?

Thanks for reading, and thanks for any help.

Pat

解决方案

Les Paul wrote:

I''m trying to design an HTML page that can edit itself. In essence, it''s
just like a Wiki page, but my own very simple version. It''s a page full
of plain old HTML content, and then at the bottom, there''s an "Edit"
link. So the page itself looks something like this:

<HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY>
<!-- TEXT STARTS HERE -->

<H1>Hello World!</H1>
<P>More stuff here...</P>

<!-- TEXT ENDS HERE -->
<A HREF="/cgi-bin/editpage.cgi?page=thisfile.html">Edit</A>
</BODY></HTML>

So if you click the "Edit" link, the CGI script goes out and reads the
body of the "thisfile.html" file. It uses those special "TEXT STARTS
HERE" tags to identify where the editable content starts and stops. It
then just dumps whatever is between those tags into a page that looks
like this:

<HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY>
<FORM ACTION="/cgi-bin/savepage.cgi" METHOD="POST">
<TEXTAREA NAME="pagetext" COLS="120" ROWS="35" WRAP="OFF">

<H1>Hello World!</H1>
<P>More stuff here...</P>

</TEXTAREA>
<INPUT TYPE=SUBMIT VALUE="Save">
</FORM>
</BODY></HTML>

So, on that page, you can edit whatever you want inside the TEXTAREA and
then click the "Save" button and the "savepage.cgi" script will write the
new data right into "thisfile.html". And so far, this works great.

But I ran into trouble as soon as I started trying to enter special
characters in the TEXTAREA. For example, I open the page and click the
"Edit" link and then start typing in fancy stuff like this:

<H1>Hello World!</H1>
<P>More stuff here...</P>
&lt;&nbsp;&nbsp; Some text &nbsp;&nbsp;&gt;

And it *seems* to work at first. When I save the page and then view it,
sure enough, I see what I''d expect, something like:

Hello World!
More stuff here...
< Some text >

But the next time I try to edit it, I can see that something has gone
horribly wrong underneath the surface. The "&nbsp;" characters are gone,
and have been replaced by some weird unicode whitespace characters (or
something?). The "&lt;" and "&gt;" get replaced by actual "<" and ">"
symbols, which is no good at all. The web browser now thinks that
"<Some text>" is some sort of tag and doesn''t display it at all. Yuck.

So I searched around a little, and I see that it''s actually standard
behavior for the <TEXTAREA> field to automatically perform conversions
like this. Ok, fine, so how do I turn this "feature" off so that
*exactly* what I type gets saved? At first, I thought that I could fix
it in my CGI script by just always expanding "<" and ">" and other
special characters back into their HTML equivalents.

But that obviously won''t work, because then it will mangle every tag in
the whole file. In fact, the text in the example above would become:

&lt;H1&gt;Hello World!&lt;/H1&gt;
&lt;P&gt;More stuff here...&lt;/P&gt;
...

Ugh. So I can''t really solve this in the script. I need to turn this
dumb behavior of the TEXTAREA off, or this just can''t work. I need for
"&lt;" to stay "&lt;" and I need for "<" to stay "<" and that''s it. Any
ideas?

Thanks for reading, and thanks for any help.



You must escape at least < and & (and any other character you want to see as
an entity instead of ''weird unicode whitespace characters'', e.g. the
character with ASCII code 160 into ''&nbsp;'') before you insert the HTML to
edit into the <textarea> in your script. Look for an apropriate function in
your programming language''s library.

The generated HTML code should look like this:

<TEXTAREA>
&lt;H1&gt;Hello World!&lt;/H1&gt;
&lt;P&gt;More stuff here...&lt;/P&gt;
&amp;lt;&amp;nbsp;&amp;nbsp; Some text &amp;nbsp;&amp;nbsp;&amp;gt;
</TEXTAREA>

The browser does not need to know that the editable text is HTML code.
The fact that browsers parse e.g. <H1> as a literal string "<H1>" instead of
a <H1> tag (that is not allowed in <TEXTAREA>) is just another case of
''over-tolerant'' behaviour that obviously causes only confusion.

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/


Benjamin Niemann <pi**@odahoda.de> wrote in

[cut]

You must escape at least < and & (and any other character you want to
see as an entity instead of ''weird unicode whitespace characters'',
e.g. the character with ASCII code 160 into ''&nbsp;'') before you
insert the HTML to edit into the <textarea> in your script. Look for
an apropriate function in your programming language''s library.

The generated HTML code should look like this:

<TEXTAREA>
&lt;H1&gt;Hello World!&lt;/H1&gt;
&lt;P&gt;More stuff here...&lt;/P&gt;
&amp;lt;&amp;nbsp;&amp;nbsp; Some text &amp;nbsp;&amp;nbsp;&amp;gt;
</TEXTAREA>

The browser does not need to know that the editable text is HTML code.
The fact that browsers parse e.g. <H1> as a literal string "<H1>"
instead of a <H1> tag (that is not allowed in <TEXTAREA>) is just
another case of ''over-tolerant'' behaviour that obviously causes only
confusion.



This is exactly what I *don''t* want to happen. I don''t want the <H1> to
be converted to anything, I want it to stay as <H1>. Likewise, I don''t
want the "&lt;" to be converted to "<". If the user types in <H1>blah
</H1> in the box, then he expects to get a page with a big, bold "blah"
on it. If he types in "&lt;" then he expects to get a page with a "<" on
it. I don''t want TEXTAREA to convert either of those for me. I can do
any type of conversion necessary in my script file, but it won''t work.

That''s what I was talking aboutwhen I said:

At first, I thought that I could fix
it in my CGI script by just always expanding "<" and ">" and other
special characters back into their HTML equivalents.

But that obviously won''t work, because then it will mangle every tag
in the whole file.



If you look at my example, here''s what the user types into the box,
exactly letter for letter (nothing has been converted yet):

<H1>Hello World</H1>
More stuff here...
&lt;&nbsp;&nbsp Some text &nbsp;&nbsp;&gt;

And then he clicks the "Save" button on the form. But before it gets to
my CGI script, it has already been mangled. So inside my perl code, this
is what the string looks like to me:

<H1>Hello World</H1>
More stuff here...
< Some text >

See the problem? How do I know which "<" and ">" characters should be
converted *back* to the HTML codes (e.g. &lt;)? It''s already too late at
this point. I have no way to know if "< Some text >" is an HTML tag
like "<H1>", or if the user really wants to have a less-than sign,
followed by three spaces, followed by "Some text" etc...

Pat


Les Paul wrote:

Benjamin Niemann <pi**@odahoda.de> wrote in

[cut]

You must escape at least < and & (and any other character you want to
see as an entity instead of ''weird unicode whitespace characters'',
...
The generated HTML code should look like this:

<TEXTAREA>
&lt;H1&gt;Hello World!&lt;/H1&gt;
&lt;P&gt;More stuff here...&lt;/P&gt;
&amp;lt;&amp;nbsp;&amp;nbsp; Some text &amp;nbsp;&amp;nbsp;&amp;gt;
</TEXTAREA>
This is exactly what I *don''t* want to happen.



Yet, it is exactly what *must* happen if this is to work correctly for
you. You simply misunderstand the reasoning behind it.
I don''t want the <H1> to be converted to anything, I want it to stay as
<H1>.
Yes, you want an <h1> to be an <h1> in the final document, but for it
must be converted for the editing process to happen correctly.

For example, if this very simplified example is the final document:

<h1>Heading</h1>

When a user selects to edit the page, you want the markup displayed
within the textarea for the user to edit and submit back, which should
look like this diagram:
______________________
|<h1>Heading</h1> |
| |
|_____________________|

The markup for that to be done correctly, needs to be this:

<textarea rows="..." cols="...">
&lt;h1&gt;Heading&lt;/h1&gt;
</textarea>

The markup your current system produces...

<textarea rows="..." cols="...">
<h1>Heading</h1>
</textarea>

....is invalid because the content of a textarea is defined as #PCDATA,
not #CDATA, so elements and entity references are supposed to be parsed
as elements and entity references, not plain text, despite the behaviour
of existing tag-soup browsers. Try running your current site through
the validator, and you''ll see what I mean.
http://validator.w3.org/
Likewise, I don''t want the "&lt;" to be converted to "<".



Then, within the textarea, your system must convert all ampersands "&"
to &amp;. That means, there anywhere an entity reference such as &amp;,
&lt; or &gt; occurs, the output must be &amp;amp;, &amp;lt;, and
&amp;gt; respectively. So, any occurance of just &amp; and &lt; and
&gt; will always be converted by the browser, but this will give you the
result you want, and is valid markup.

So, to extend the previous example, the text area markup could look like
this (I''ve added spaces for easier reading):

<textarea rows="..." cols="...">
&lt;h1&gt;Heading&lt;/h1&gt;

&lt;p&gt; &amp;lt; Some&amp;nbsp;Content &amp;gt; &lt;/p&gt;
</textarea>

When submitted, you system should convert all of &amp;, &lt; &gt; back
to &, < and >, respectively. So, when the above is submitted, the final
output markup should be:

<h1>Heading</h1>

<p> &lt; Some&nbsp;Content &gt; </p>

I hope this explains it clearly enough for you.

--
Lachlan Hunt
http://lachy.id.au/
http://GetFirefox.com/ Rediscover the Web
http://GetThunderbird.com/ Reclaim your Inbox


这篇关于&lt; TEXTAREA&gt;是一件奇怪的事。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆