值不会分配给数组(javascript) [英] Value won't assign to array (javascript)

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

问题描述

我正在使用jquery方法$(this).html()来获取按钮的值。

I'm using the jquery method $(this).html() to get the value of a button.

当我将值分配给变量(例如 x = $(this).html();

It works fine when I assign the value to a variable (like x = $(this).html();)

我尝试将值分配给数组(例如 expression [1] = $(this).html();

But won't work when I try to assign the value to an array (like expression[1] = $(this).html();)

A

// expression = array();


$(document).ready(function()
                {
                    $(".operator").click(function(){

        expression[0] = $(this).html(); //
        alert(expression[0]);           // Won't work

        // x = $(this).html();          // Works
        // alert(x);                    //


                  });
               });

我在做什么错了?

推荐答案

您的数组不存在。

您需要先创建它:

Your array doesn't exist.
You need to create it first:

var expression = [];   //Array literal

这篇关于值不会分配给数组(javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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