English 中文(简体)
Java双维阵列
原标题:Javascript two-dimensional array

我想在 j印功能中建立一个两个层面阵列。 我发现应该这样做的法典,但却没有。 我宣布该阵列后确定了增加阵列要素的职能。

    // Array function
    var card_array = new Array();
    function card_array(card_id, card_top, card_left) {
        alert( array );
        this.card_id = card_id;
        this.card_top = card_top;
        this.card_left = card_left;
    }

    // Toggle LinkCard minimize/expand
    function toggle_linkcard(toggle, card_id) {

        var icard = 0; 
        $( .linkcard ).each(function () {
            card_top = $(this).position().top;
            card_left = $(this).position().left;
            card_i = $(this).attr( id );
            card_array[card_array.length++] = new card_array(card_i, card_top, card_left);
            icard++;
        });
        alert(card_array);

    }

我在阵列中添加内容的守则线打破了该守则。

            card_array[card_array.length++] = new card_array(card_i, card_top, card_left);

我应该确定什么?

最佳回答

您将职务名称定义为card_array,与变量名称相同。 因此,在这一条码线之后,你没有哪一个变量的名称是card_array,但只有这一功能。 更改您的变量或功能名称。

问题回答

这里的问题是,你有两种同名的价值观:卡姆拉里。

  • A variable named which is initialized to a new Array()
  • A function which takes 3 parameters

The function declaration happens last and hence wins. So when you execute the expression card_array[card_array.length++] you are doing so on a function instance, not an array.

将这一更改的名称限定为独一无二的名称。

仅此改动:

var card_array = new Array();

页: 1

var my_card_array = new Array();

而且:

card_array[card_array.length++] = new card_array(card_i, card_top, card_left);

页: 1

my_card_array.push(new card_array(card_i, card_top, card_left));

当然,改变警示。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签