问题描述
我不能得到任何普遍的代码工作试图检测它所在的
文件是xhtml还是html。
我发现了这个,它告诉我我有一座小山要爬设备。
如果可以,我打算使用document.doctype属性,但显然
除非另有说明我用严格。 (只是尝试过Strict,仍然是
什么都不做)。
这就是我所拥有的。任何人都有想法可行或有些指针?我现在没有任何钱买书,我也不知道可以选择哪一本100美元的JS书籍。
我使用的是IE6,但我希望这是跨浏览器。
<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns =" http://www.w3.org/1999/xhtml">
< head>
< meta http-当量= QUOT;内容类型"含量=" text / html的;字符集= ISO-8859-1" />
< title> Untitled Document< / title>
< / head>
< body>
< script language =" JavaScript" type =" text / javascript">
//document.getElementsByTagName('''DOCTYPE'')生成一个对象,但是什么
类型?元件?如果是这样,为什么元素属性不起作用?
document.write(document.doctype); //什么都不打印
document.write(document.getElementsByTagName(''html'')。getAttribute(" xmlns"));
//什么都不打印
document.write(document.getElementsByTagName(''!DOC TYPE'')。hasAttribute(" - // W3C // DTD
XHTML 1.0 Transitional // EN") ); //什么都不打印
// if(document.getElementsByName(''!DOCTYPE'')!= null ||
document.getElementsByName(''html'') .getAttribute(''x mlns'')!= null){
// document.write(document.getElementsByName(''html'')。innerHTML);
//}
< / script>
< / body>
< / html>
我真的很沮丧。我缺少信息。
Jim Michaels
I can''t get any "universal" code working that tries to detect whether the
document it''s in is xhtml or html.
I found this, which tells me I have a hill to climb with no equipment.
http://javascript.about.com/library/bliebug.htm
I was going to use the document.doctype property if I could, but apparently
that isn''t available unless I use strict. (just tried it with Strict, still
doesn''t do anything).
here''s what I''ve got. anybody got ideas that work or some pointers? I
don''t have any money for books right now, and I wouldn''t know which of 100''s
of JS books to pick from.
I am using IE6, but I want this to be cross-browser.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
//document.getElementsByTagName(''!DOCTYPE'') generates an "object", but what
type? element? if so, why won''t element properties work?
document.write(document.doctype); //prints nothing
document.write(document.getElementsByTagName(''html '').getAttribute("xmlns"));
//prints nothing
document.write(document.getElementsByTagName(''!DOC TYPE'').hasAttribute("-//W3C//DTD
XHTML 1.0 Transitional//EN")); //prints nothing
//if (document.getElementsByName(''!DOCTYPE'') != null ||
document.getElementsByName(''html'').getAttribute(''x mlns'') != null) {
// document.write(document.getElementsByName(''html''). innerHTML);
//}
</script>
</body>
</html>
I''m really frustrated. I lack info.
Jim Michaels
推荐答案
首先为什么你需要知道它?
Why do you need to know it, first of all?
因为生成的单例元素不同,例如< bror< br />
,具体取决于它是否为html或者xhtml。
because generated singleton elements are different, such as <bror <br />
depending on whether it''s html or xhtml.
因为生成的单例元素不同,例如< bror< br />
,具体取决于它是否是html或者xhtml。
because generated singleton elements are different, such as <bror <br />
depending on whether it''s html or xhtml.
你想用它们做什么?你可以使用相同的javascript
调用来制作,获取或操纵它们,无论
文本的格式如何?我对xhtml不是很熟悉我只是在想它是不是很难有可能没必要。
What are you trying to do with them? Can you use the same javascript
calls to make, get or manipulate them, regardless of the format of the
text? I''m not very familiar with xhtml I''m just thinking if it''s so
hard it might not be necessary.
这篇关于DOCTYPE探测器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!