开发者

How to pass value to using external variable in javascript?

following code works properly

draw([['Rice',20,28,38],['Paddy',31,38,55],]);

but when i try using external variable like

开发者_如何学Pythonvar val1=20;
var val2=30;
var val3=40;
draw([['Rice',val1,val2,val3],['Paddy',31,38,55],]);

It wont work.


Just showing that your example code works fine using the Firebug console. Can you post more of your code? Your stripped-down example is probably missing something else that's causing a problem.

What is your draw() function doing? Could something in that function be breaking?

EDIT: Another problem could be the trailing comma after your second array. That will throw an error in Internet Explorer.

alert([['Rice',val1,val2,val3],['Paddy',31,38,55],]);

should be:

alert([['Rice',val1,val2,val3],['Paddy',31,38,55]]);

That may solve your issue (though you also have that in your 'working' example, but I thought it worth mentioning).

How to pass value to using external variable in javascript?


Your code snippets are not equivalent -- the second one has different values (['Rice',20,30,40] vs ['Rice',20,28,38]). Other than that, they are equivalent and should have the same effects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜