数组怀疑,(初学者问题) [英] Doubt in Array , (beginner question)

查看:91
本文介绍了数组怀疑,(初学者问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的小组,

请查看以下函数定义:


函数at_show_aux(父,子)

{

var p = document.getElementById(parent);

var c = document.getElementById(child);


var top =(c [" at_position"] ==" y")? p.offsetHeight + 2:0;

var left =(c [" at_position"] ==" x")? p.offsetWidth +2:0;


for(; p; p = p.offsetParent)

{

top + = p.offsetTop;

left + = p.offsetLeft;

}


c.style.position =" absolute" ;;

c.style.top = top +''px'';

c.style.left = left +''px'';

c.style.visibility =" visible";

}


变量c未声明为Array对象,但它是操作的

因为它是一个数组。我在谷歌搜索了关键词javascript

array,但它只解释了用Array()声明的变量

对象。任何人都可以指向一个初学者的正确来源。谢谢。

Dear group,
pls go through the following function definition:

function at_show_aux(parent, child)
{
var p = document.getElementById(parent);
var c = document.getElementById(child);

var top = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

for (; p; p = p.offsetParent)
{
top += p.offsetTop;
left += p.offsetLeft;
}

c.style.position = "absolute";
c.style.top = top +''px'';
c.style.left = left+''px'';
c.style.visibility = "visible";
}

The variable c is not declared as a Array object, but it was manipulate
as is it is a array.I searched the google for the key word "javascript
array", but it all explains only about the variable declared with Array()
object. Can any one point me to the correct source for a Beginner.Thanks.

推荐答案

sathyashrayan写道:
sathyashrayan wrote:

亲爱的小组,

请参阅以下函数定义:


函数at_show_aux(父母,孩子)

{

var p = document.getElementById(parent);

var c = document.getElementById(child);


var top =(c [" at_position"] ==" y")? p.offsetHeight + 2:0;

var left =(c [" at_position"] ==" x")? p.offsetWidth +2:0;


for(; p; p = p.offsetParent)

{

top + = p.offsetTop;

left + = p.offsetLeft;

}


c.style.position =" absolute" ;;

c.style.top = top +''px'';

c.style.left = left +''px'';

c.style.visibility =" visible";

}


变量c未声明为Array对象,但它是操作的

因为它是一个数组。我在谷歌搜索了关键词javascript

array,但它只解释了用Array()声明的变量

对象。任何人都可以指向初学者的正确来源。谢谢。
Dear group,
pls go through the following function definition:

function at_show_aux(parent, child)
{
var p = document.getElementById(parent);
var c = document.getElementById(child);

var top = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

for (; p; p = p.offsetParent)
{
top += p.offsetTop;
left += p.offsetLeft;
}

c.style.position = "absolute";
c.style.top = top +''px'';
c.style.left = left+''px'';
c.style.visibility = "visible";
}

The variable c is not declared as a Array object, but it was manipulate
as is it is a array.I searched the google for the key word "javascript
array", but it all explains only about the variable declared with Array()
object. Can any one point me to the correct source for a Beginner.Thanks.






这种符号被命名为关联数组符号(或者类似的东西)。

例如:

var myObject = new Object();

myObject [" firstname"] =" sathyashrayan" ;;

myObject [" favlang"] =" JavaScript";


创建了一个新对象,并为其添加了两个''哈希''及其值。

您可以将它们视为不使用数字的插槽或数组索引,但

a字符串指向某个地方。

这有时被称为属性对象。

您也可以写:

myObject.firstname


他们可以保存其他对象,如数组,或者字符串,或者你可以存储在变量中的任何东西。

他们派上用场来创建你自己的数据结构。


在你的情况下,你通过getElementById()获得了名为c的对象。

好​​像是ct hing包含一个名为''at_position''的哈希/属性,

不是我所知的标准属性。


问候,

Erwin Moller

Hi,

That notation is named associative Array notation (or something like that).
example:
var myObject = new Object();
myObject["firstname"] = "sathyashrayan";
myObject["favlang"] = "JavaScript";

That created a new object, and added 2 ''hashes'' to it with their values.
You can think of them as slots or arrayindexes that do not use a number, but
a string to point to a certain place.
This is sometimes refered to as properties of the Object.
You can also write:
myObject.firstname

They can hold other Objects, like array, or strings, or anything that you
can store in a variable.
They come in handy to create your own datastructures.

In your case you got your Object named c via getElementById().
Appearantly that c thing contains a hash/property named ''at_position'', which
is not a standard property to my knowledge.

Regards,
Erwin Moller




sathyashrayan写道:

sathyashrayan wrote:

亲爱的小组,

请参阅以下函数定义:


函数at_show_aux(父,子)

{

var p = document.getElementById(parent);

var c = document.getElementById(child);


var top =( c [" at_position"] ==" y")? p.offsetHeight + 2:0;

var left =(c [" at_position"] ==" x")? p.offsetWidth +2:0;


for(; p; p = p.offsetParent)

{

top + = p.offsetTop;

left + = p.offsetLeft;

}


c.style.position =" absolute" ;;

c.style.top = top +''px'';

c.style.left = left +''px'';

c.style.visibility =" visible";

}


变量c未声明为Array对象
Dear group,
pls go through the following function definition:

function at_show_aux(parent, child)
{
var p = document.getElementById(parent);
var c = document.getElementById(child);

var top = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

for (; p; p = p.offsetParent)
{
top += p.offsetTop;
left += p.offsetLeft;
}

c.style.position = "absolute";
c.style.top = top +''px'';
c.style.left = left+''px'';
c.style.visibility = "visible";
}

The variable c is not declared as a Array object



它在一个语句中声明和初始化,其值设置为

document.getElementById(child)返回的任何内容,大概是一个

DOM元素。

It is declared and initialised in one statement, its value is set to
whatever is returned by document.getElementById(child), presumably a
DOM element.


但它被操作,因为它是一个数组。
but it was manipulate as is it is a array.



它被视为对象的引用。从后续代码中可以看出,该脚本的作者已在其他地方扩展了主机DOM对象,以包含at_position和/或
。属性。


DOM对象的这种扩展不包含在ECMAScript或
W3C规范中,因此它取决于浏览器并且很可能在

至少一些浏览器(如果不是大多数)。一个更广泛支持的方法

将在源HTML中添加属性并使用

元素的getAttribute方法访问它:


< div id =" divA" at_position =" x" ...< / div>


< script type =" text / javascript">

var d = document.getElementById(''divA'');

alert(d.getAttribute(''at_position''));

< / script>

你可能想读这个帖子:


< URL:
http://groups.google.com/ group / comp .... bf1f5cf9f6b69a


>
>



或搜索标题为Instantiate extended browser objects的帖子

-

Rob

or search for the thread titled "Instantiate extended browser objects"
--
Rob


RobGaécrit:
RobG a écrit :

更广泛支持的方法

将在源HTML
A more widely supported method
would be to add the property in the source HTML



中添加属性W3C的验证器将对这些奇怪的进行说明。属性?


由JS分配这些属性也不是更好吗?

what would say W3C''s validator about these "strange" attributes ?

wouldn''t it be better to assign these attributes by JS too ?


并使用

元素'的getAttribute方法:


< div id =" divA" at_position =" x" ...< / div>


< script type =" text / javascript">

var d = document.getElementById(''divA'');

alert(d.getAttribute(''at_position''));

< / script>
and access it using the
element''s getAttribute method:

<div id="divA" at_position="x"... </div>

<script type="text/javascript">
var d = document.getElementById(''divA'');
alert( d.getAttribute( ''at_position'' ) );
</script>


这篇关于数组怀疑,(初学者问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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