IE不是DOM的风格? [英] IE not DOM for style?

查看:77
本文介绍了IE不是DOM的风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



只是我,还是

obj.setAttribute(style,border:thin solid navy);

(例如 - 似乎没有设置样式)在IE6中不起作用但在NN6中工作正常




我不想要使用element.style [.cssText]只是因为。

任何想法?


测试文件:


< html>

< head>

< title> Javascript测试 - 动态元素< / title>


< ; script type =" text / javascript" language =" javascript">

函数createDiv(divId,appendElement)

{

STYLE =" border:thin solid solid heavy;宽度:300px;身高:300px;" ;;


//创建

D = document.createElement(" div");


//设置属性

D.setAttribute(" id",divId);

D.setAttribute(" style",STYLE);


//追加元素

appendElement.appendChild(D);

}


function testRun()

{

createDiv(" div1",document.getElementById(" target"));

}

< / script>

< / head>


< body>

<表格名称=" f1">

< p>

< input type =" button"名称= QUOT; B1" value =" test it" onClick =" testRun()">

< / p>

< / form>

< div id = " target">< / div>

< / body>

< / html>


- ------------------------------------------------ <无线电通信/>
~kaeli~

按任意键继续或任何其他键退出。

谁是一般失败,为什么他在读?

我的硬盘?
http://www.ipwebdesign.net/ wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

---------------------------------------- ---------

解决方案

请纠正我,如果我错了,但风格是一个对象,而不是一个字符串。

当你做style =" width:2.46em"在HTML

元素的定义中,它实际上是.style.width =" 2.46em的缩写。

我会认为NN特别慷慨处理

你的方法。下面的代码段显示你可以在IE中使用带有样式对象的

setAttribute。


来自纽约的Csaba Gabor


< body onLoad =" makeBorder()">

< script type =" text / javascript">

function makeBorder() {

var myDiv = document.getElementById(" myDiv");

myStyle = myDiv.style;

myStyle.border ="薄实心海军蓝; //这显示下一行有效

myDiv.setAttribute(" style",myStyle);

}

< / script>

< div id =" myDiv">嗨妈妈< / div>

< body>

" kaeli" <在******************** @ NOSPAMatt.net>在留言新闻中写道:MP ************************ @ nntp.lucent.com ...


它只是我,还是
obj.setAttribute(style,border:thin solid navy);
(例如 - 似乎没有设置样式)在IE6中不起作用但在NN6中工作正常吗?

我不想仅仅因为使用element.style [.cssText]。
任何想法?
测试文件:

< html>
< head>
< title> Javascript测试 - 动态元素< / title>

< ; script type =" text / javascript" language =" javascript">
函数createDiv(divId,appendElement)
{
STYLE =" border:thin solid rhavy;宽度:300px;身高:300px;" ;;

//创建
D = document.createElement(" div");

//设置属性
D.setAttribute(id,divId);
D.setAttribute(style,STYLE);

//追加元素
appendElement.appendChild(D) ;


函数testRun()
{
createDiv(" div1",document.getElementById(" target"));
}
< / script>
< / head>

< body>
< form name =" f1">
< ; p>
< input type =" button"名称= QUOT; B1" value =" test it" onClick =" testRun()">
< / p>
< / form>
< div id =" target">< / div>
< / body>
< / html>

------------------------- ------------------------
〜kaeli~
按任意键继续或任何其他键退出。
谁是一般失败,他为什么要阅读我的硬盘?
http://www.ipwebdesign.net/wildAtHeart
http:/ /www.ipwebdesign.net/kaelisSpace
---------------------------------- ---------------



>如果我错了,请纠正我,但风格是一个对象,而不是一个字符串。


我认为这是一个实现问题,浏览器如何暴露

样式对象。


也就是说,已知setAttribute在IE中非常错误且不可靠。

当你没有使用它时可以使用style.xxx。


问候,

Svend


在文章< bi ********@dispatch.concentric.net>, ne**@CsabaGabor.com

启发我们...

如果我错了,请纠正我,但风格是一个对象,而不是一个字符串。


实际上,根据DOM,大多数(如果不是全部)属性是对象的属性,并且

甚至是对象本身。你传递的字符串是该对象的

名称。


--------

createAttribute

创建给定名称的Attr。请注意,Attr实例可以使用setAttributeNode方法在元素上设置



Attr接口表示Element对象中的属性。 />
通常,属性的允许值在

文档类型定义中定义。

Attr对象继承Node接口,


setAttribute

添加新属性。如果元素中存在具有该名称的属性,则其值将更改为值

参数的值。

- ----------

样式是一个对象,但它也是其他对象的属性。
http://www.mozilla.org/docs/dom/domr...style_ref.html


我会认为NN在处理你的方法方面非常慷慨。


不,这是DOM,至少根据这些家伙来说......

http://www.webreference.com/programm...apps/chap5/2/3

..html

http://www.csie.ntu.edu.tw/~b7506051...style_ref.html

http://www.w3.org/TR/ 2000 / REC-DOM-Le ... 1113 / core.html

下面的代码段显示你可以在IE中使用
setAttribute和样式对象。



谢谢。但最终目标是将整个样式

定义作为字符串传递给函数,因此设置每个部分不是

选项。我想我会使用课程。


我认为IE在这个上有错误。

*叹气*

我曾经不得不担心NN4。现在我找到了这个。

好​​吧。


---------------------- ---------------------------

~kaeli~

按任意键即可继续或任何其他关键退出。

谁是一般失败,为什么他在阅读我的硬盘?$ / b
我的硬盘?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

----------- --------------------------------------



Is it just me, or does
obj.setAttribute("style","border: thin solid navy");
(for example - no style seems to be set) not work in IE6 but works fine
in NN6?

I don''t want to use element.style[.cssText] just because.
Any ideas?

Test file:

<html>
<head>
<title>Javascript test - dynamic elements</title>

<script type="text/javascript" language="javascript">
function createDiv(divId, appendElement)
{
STYLE="border: thin solid navy; width: 300px; height: 300px;";

// create
D = document.createElement("div");

// set attributes
D.setAttribute("id",divId);
D.setAttribute("style",STYLE);

// append element
appendElement.appendChild(D);
}

function testRun()
{
createDiv("div1",document.getElementById("target") );
}
</script>
</head>

<body>
<form name="f1">
<p>
<input type="button" name="b1" value="test it" onClick="testRun()">
</p>
</form>
<div id="target"></div>
</body>
</html>

-------------------------------------------------
~kaeli~
Press any key to continue or any other key to quit.
Who is General Failure and why is he reading
my hard disk?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------

解决方案

Please correct me if I''m wrong, but style is an object and not a string.
When you do style="width:2.46em" in the definition of an HTML
element, it''s actually shorthand for .style.width="2.46em".
I would opine that NN is exceptionally generous in dealing with
your approach. The snippet below shows that you can use
setAttribute in IE with the style object.

Csaba Gabor from New York

<body onLoad="makeBorder()">
<script type="text/javascript">
function makeBorder() {
var myDiv = document.getElementById("myDiv");
myStyle = myDiv.style;
myStyle.border = "thin solid navy"; // this shows the next line works
myDiv.setAttribute("style", myStyle);
}
</script>
<div id="myDiv">Hi Mom</div>
<body>
"kaeli" <in********************@NOSPAMatt.net> wrote in message news:MP************************@nntp.lucent.com...


Is it just me, or does
obj.setAttribute("style","border: thin solid navy");
(for example - no style seems to be set) not work in IE6 but works fine
in NN6?

I don''t want to use element.style[.cssText] just because.
Any ideas?

Test file:

<html>
<head>
<title>Javascript test - dynamic elements</title>

<script type="text/javascript" language="javascript">
function createDiv(divId, appendElement)
{
STYLE="border: thin solid navy; width: 300px; height: 300px;";

// create
D = document.createElement("div");

// set attributes
D.setAttribute("id",divId);
D.setAttribute("style",STYLE);

// append element
appendElement.appendChild(D);
}

function testRun()
{
createDiv("div1",document.getElementById("target") );
}
</script>
</head>

<body>
<form name="f1">
<p>
<input type="button" name="b1" value="test it" onClick="testRun()">
</p>
</form>
<div id="target"></div>
</body>
</html>

-------------------------------------------------
~kaeli~
Press any key to continue or any other key to quit.
Who is General Failure and why is he reading
my hard disk?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------



> Please correct me if I''m wrong, but style is an object and not a string.

I think this is an implementation question, how the browser exposes the
style object.

That said, setAttribute is known to be very buggy and unreliable in IE.
Just don''t use it when you can use style.xxx instead.

Regards,
Svend


In article <bi********@dispatch.concentric.net>, ne**@CsabaGabor.com
enlightened us with...

Please correct me if I''m wrong, but style is an object and not a string.
Actually, most (if not all) attributes are properties of objects and
even object themselves, according to the DOM. The string you pass is the
name of that object.

--------
createAttribute
Creates an Attr of the given name. Note that the Attr instance can
then be set on an Element using the setAttributeNode method.

The Attr interface represents an attribute in an Element object.
Typically the allowable values for the attribute are defined in a
document type definition.

Attr objects inherit the Node interface,

setAttribute
Adds a new attribute. If an attribute with that name is already
present in the element, its value is changed to be that of the value
parameter.
-----------
Style is an object, but it is also a property of other objects.
http://www.mozilla.org/docs/dom/domr...style_ref.html

I would opine that NN is exceptionally generous in dealing with
your approach.
No, that is DOM, at least according to these guys...

http://www.webreference.com/programm...apps/chap5/2/3
..html

http://www.csie.ntu.edu.tw/~b7506051...style_ref.html

http://www.w3.org/TR/2000/REC-DOM-Le...1113/core.html
The snippet below shows that you can use
setAttribute in IE with the style object.



Thanks. But the ultimate goal is (was) to pass an entire style
definition as a string to a function, so setting each piece is not an
option. I guess I''ll use classes instead.

I think IE is buggy on this one.
*sigh*
I used to have to worry about NN4. Now I find this.
Oh well.

-------------------------------------------------
~kaeli~
Press any key to continue or any other key to quit.
Who is General Failure and why is he reading
my hard disk?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------


这篇关于IE不是DOM的风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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