1
我有一個數據集作爲如何通過jQuery中的字符串值調用變量?
var data1 = {values:[
{ X: "33", Y: 12 },
....
]};
var data2 = { values:[
{ X: "Jan", Y: 2 },
...
]};
我想我怎樣才能創建一個從靜態值var data
加載相應的數據通過
$(document).ready(function() {
$(".test").click(function(){
var data = $(this).val() // the value will be data1 or data2
// how can I make the data a JSON equal to data1 or data2 instead of
// assigning the static value of $(this).val() to it.
}
});
設置?
https://developer.mozilla.org/zh/JavaScript/Reference/Operators/Member_Operators#Bracket_notation –