在脚本编写中应用HTML 4.01 DOM的问题 [英] Problem applying HTML 4.01 DOM in scripting

查看:41
本文介绍了在脚本编写中应用HTML 4.01 DOM的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我已经接受了一些人的建议,并设法凑齐了一个

HTML 4.01严格兼容的文件(根据W3C验证

服务),但是我尝试将TextArea对象传递给脚本的方式

函数不起作用。


我可以做的最少的改变是保持

兼容,但也正确执行?


TIA ,

Richard


<!DOCTYPE html PUBLIC" - // W3C // DTD HTML 4.01 // EN"

http://www.w3.org/TR/html4/strict.dtd">

< html>

< head>

< title> AnHTML 4.01 Strict"合规文件< / title>

< meta http-equiv =" Content-Style-Type"含量="文本/ CSS" >

< meta http-equiv =" content-type"

content =" text / html; charset = ISO-8859-1" >

< style type =" text / javascript">

#red {color:red}

.blue {color :blue}

< / style>


< script type =" text / javascript">

函数GenLines(o,n)

{

var aL = []; //数组行,没有换行符,这将是
填充MyTextArea

//与换行符分隔符连接时

// if((o = o.form)&&(o = o.elements)&&(o = o [''MyTextArea'']))

{

for(var i = 1; i< = n; i ++)

{

aL.push(" Line" + i);

}

o.value = aL.join(" \ n");

}

}

< / script>


< / head>

< body>

< div>

< p>

...这里的HTML内容...< / p>

< p id =" red" ;>

DOCTYPE是安全带对于HTML作者< / p>

< p>< b class =" blue"> Item 1< / b> < i>第2项< / i>< / p>

< input id =" Button1"类型= QUOT按钮" value ="点击12行>

onclick =" GenLines(MyTextArea,12)" />

< br />

< br />

< input id =" MyTextArea" style =" width:420px;身高:122px"

type =" text" />< / div>

< / body>

< / html>

Hi All,

I''ve taken the advice of a few people and managed to cobble together an
HTML 4.01 Strict-compliant document (according to the W3C Validation
Service), but the way I try to pass a TextArea object to a script
function doesn''t work.

What''s the least amount of change I can make to this to remain
compliant but also correct for execution?

TIA,
Richard

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>An "HTML 4.01 Strict" compliant document</title>
<meta http-equiv="Content-Style-Type" content="text/css" >
<meta http-equiv="content-type"
content="text/html;charset=ISO-8859-1" >
<style type="text/javascript">
#red {color:red}
.blue {color:blue}
</style>

<script type="text/javascript">
function GenLines(o, n)
{
var aL = []; // Array of lines, sans newlines, which will
populate MyTextArea
// when concatenated with newline separators
// if ((o = o.form) && (o = o.elements) && (o = o[''MyTextArea'']))
{
for (var i=1; i<=n; i++)
{
aL.push("Line " + i);
}
o.value = aL.join("\n");
}
}
</script>

</head>
<body>
<div>
<p>
... Your HTML content here ...</p>
<p id="red">
DOCTYPEs are "seatbelts" for HTML authors</p>
<p><b class="blue">Item 1</b> <i>Item 2</i></p>
<input id="Button1" type="button" value="Click for 12 lines"
onclick="GenLines(MyTextArea, 12)" />
<br />
<br />
<input id="MyTextArea" style="width: 420px; height: 122px"
type="text" /></div>
</body>
</html>

推荐答案

Richard Lionheart写道:
Richard Lionheart wrote:
,但我尝试将TextArea对象传递给脚本
函数的方式不起作用。
< input id =" Button1"类型= QUOT按钮" value ="点击12行>
onclick =" GenLines(MyTextArea,12)" />


MyTextArea是一个未定义的变量。你可能想要这样的东西:

onclick =" GenLines(this.form.elements [''MyTextArea''],12);"

< br / >
不要在HTML中使用XHTML样式的自闭项标签。它们的含义是不同的。

< input id =" MyTextArea" style =" width:420px;身高:122px"
type =" text" />< / div>
, but the way I try to pass a TextArea object to a script
function doesn''t work. <input id="Button1" type="button" value="Click for 12 lines"
onclick="GenLines(MyTextArea, 12)" />
MyTextArea is an underfined variable. You probably want something like:
onclick="GenLines(this.form.elements[''MyTextArea''], 12);"
<br /> Don''t use XHTML style self closing tags in HTML. Their meaning is different.
<input id="MyTextArea" style="width: 420px; height: 122px"
type="text" /></div>




-

David Dorward< http://blog.dorward.me.uk/ > < http://dorward.me.uk/>

首页是〜/ .bashrc的位置



--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is




Richard Lionheart写道:

Richard Lionheart wrote:
大家好,

我已经接受了一些人的建议,并设法凑齐了一个
HTML 4.01严格兼容的文档(根据W3C Validation
服务),但我尝试将TextArea对象传递给脚本
函数的方式不起作用。

什么我可以做出最少的改变,以保持合规性,但也可以正确执行?TIA,
理查德

< ;!DOCTYPE html PUBLIC" - // W3C // DTD HTML 4.01 // EN"
" http://www.w3.org/TR/html4/strict.dtd">
< html>
< head>
< title> AnHTML 4.01 Strict"兼容文件< / title>
< meta http-equiv =" Content-Style-Type"含量="文本/ CSS" >
< meta http-equiv =" content-type"
content =" text / html; charset = ISO-8859-1" >
< style type =" text / javascript">
#red {color:red}
.blue {color:blue}
< / style>

< script type =" text / javascript">
函数GenLines(o,n)
{
var aL = []; //数组行,无新行,当与换行符分隔符连接时将填充MyTextArea
// if((o = o.form)&&(o = o.elements)&&(o = o [''MyTextArea'']))
{
for(var i = 1; i< = n; i ++)
{
aL.push(" Line" + i);
}
o.value = aL.join(" \ n");
}
}
< / script>
< / head>
< body>
< div>
< p>
...您的HTML内容...< / p>
< p id =" red">
DOCTYPE是安全带对于HTML作者< / p>
< p>< b class =" blue"> Item 1< / b> < i>第2项< / i>< / p>
< input id =" Button1"类型= QUOT按钮" value ="点击12行>
onclick =" GenLines(MyTextArea,12)" />
< br />
< br />
< input id =" MyTextArea" style =" width:420px;身高:122px"
type =" text" />< / div>
< / body>
< / html>
Hi All,

I''ve taken the advice of a few people and managed to cobble together an
HTML 4.01 Strict-compliant document (according to the W3C Validation
Service), but the way I try to pass a TextArea object to a script
function doesn''t work.

What''s the least amount of change I can make to this to remain
compliant but also correct for execution?

TIA,
Richard

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>An "HTML 4.01 Strict" compliant document</title>
<meta http-equiv="Content-Style-Type" content="text/css" >
<meta http-equiv="content-type"
content="text/html;charset=ISO-8859-1" >
<style type="text/javascript">
#red {color:red}
.blue {color:blue}
</style>

<script type="text/javascript">
function GenLines(o, n)
{
var aL = []; // Array of lines, sans newlines, which will
populate MyTextArea
// when concatenated with newline separators
// if ((o = o.form) && (o = o.elements) && (o = o[''MyTextArea'']))
{
for (var i=1; i<=n; i++)
{
aL.push("Line " + i);
}
o.value = aL.join("\n");
}
}
</script>

</head>
<body>
<div>
<p>
... Your HTML content here ...</p>
<p id="red">
DOCTYPEs are "seatbelts" for HTML authors</p>
<p><b class="blue">Item 1</b> <i>Item 2</i></p>
<input id="Button1" type="button" value="Click for 12 lines"
onclick="GenLines(MyTextArea, 12)" />
<br />
<br />
<input id="MyTextArea" style="width: 420px; height: 122px"
type="text" /></div>
</body>
</html>




这是对当地公众的检查吗? ;-)


此页面可能不是任何类型的有效HTML,因为它

使用XHTML标记格式/>


另外input = text接受*单行文本*。对于多行文字,您使用

< textarea>。也......无论如何,没有最小变化。在这里 - 它完全重写了

。研究有效变体,请不要犹豫

询问是否有一些变化不明确:


<!DOCTYPE html PUBLIC" - // W3C / / DTD HTML Strict 4.01 // EN"

" http://www.w3.org/TR/html401/strict.dtd">

< html> ;

< head>

< title> AnHTML 4.01 Strict"合规文件< / title>

< meta http-equiv =" Content-Type"

content =" text / html; charset = iso-8859-1">

< style type =" text / css">

#red {color:red}

.blue {color:blue}

< / style>

< script type =" text / javascript">

函数GenLines(o,n){

var aL = [];

for(var i = 0; i< = n; i ++){

aL.push(" Line" + i);

}

o.value = aL.join(" \ n" );

}

< / script>

< / head>

< body>

< p>

...这里的HTML内容...< / p>

< p id =" red" ;>

DOCTYPE是安全带对于HTML作者< / p>

< p>< b class =" blue"> Item 1< / b> < i>第2项< / i>< / p>

< form action ="">

< fieldset>

< legend> Hello W3C world!< / legend>

< input id =" Button1"类型= QUOT按钮" value ="点击12行>

onClick =" GenLines(this.form.elements [''MyTextArea''],12)">

< br>

< br>

< textarea name =" MyTextArea" COLS = QUOT; 20" rows =" 12">< / textarea>

< / fieldset>

< / form>

< /正文>

< / html>



Was it a check for local public? ;-)

This page cannot possibly be a valid HTML of any kind just because it
uses XHTML tag format />

Also input=text accepts *single line text*. For multiline text you use
<textarea>. Also... any way, there is no "minimum change" here - it has
to be completely rewritten. Study the valid variant, do not hesitate to
ask if some changes are not clear:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML Strict 4.01//EN"
"http://www.w3.org/TR/html401/strict.dtd">
<html>
<head>
<title>An "HTML 4.01 Strict" compliant document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
#red {color:red}
.blue {color:blue}
</style>
<script type="text/javascript">
function GenLines(o, n) {
var aL = [];
for (var i=0; i<=n; i++) {
aL.push("Line " + i);
}
o.value = aL.join("\n");
}
</script>
</head>
<body>
<p>
... Your HTML content here ...</p>
<p id="red">
DOCTYPEs are "seatbelts" for HTML authors</p>
<p><b class="blue">Item 1</b> <i>Item 2</i></p>
<form action="">
<fieldset>
<legend>Hello W3C world!</legend>
<input id="Button1" type="button" value="Click for 12 lines"
onClick="GenLines(this.form.elements[''MyTextArea''],12)">
<br>
<br>
<textarea name="MyTextArea" cols="20" rows="12"></textarea>
</fieldset>
</form>
</body>
</html>


VK写道:
VK wrote:
这个页面不可能是任何类型的有效HTML,因为它使用XHTML标记格式/>
This page cannot possibly be a valid HTML of any kind just because it
uses XHTML tag format />




实际上,它可以。


< foo />与< foo>>相同因此< foo>& gt;在HTML中。因此,只要您允许任何字符数据,您就可以使用XHTML样式的自动关闭标签,并且

有效。 (所以< img>和< br>,以及在某些情况下< hr>)。

当然,虽然它是有效的,但这并不意味着什么你试图说,所以

应该避免。 (你不能指望Markup Validator在这个错误上选择

)。


-

David Dorward< http://blog.dorward.me.uk/> < http://dorward.me.uk/>

首页是〜/ .bashrc的位置



Actually, it can.

<foo /> means the same as <foo>> and thus <foo>&gt; in HTML. So anywhere you
are allowed character data, you can use XHTML style self-closing tags and
be valid. (So <img> and <br>, along with <hr> in some circumstances).

Of course, while it is valid, it doesn''t mean what you are trying to say, so
it should be avoided. (You just can''t expect the Markup Validator to pick
up on that error).

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is


这篇关于在脚本编写中应用HTML 4.01 DOM的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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