向值为对象的数组中添加键/值
我想添加一些文本作为键,对象作为值。
例子
$('#clickme').on('click' , function() {
push to array => "some_text" as (value) and $(this) as key
})
向值为对象的数组中添加键/值
我想添加一些文本作为键,对象作为值。
例子
$('#clickme').on('click' , function() {
push to array => "some_text" as (value) and $(this) as key
})
只需使用一个普通对象,它可以像关联数组一样工作:
var myObj = {};
$('#clickme').on('click' , function() {
myObj["some_text"] = $(this);
});
var value = myObj["some_text"];
- njr101这应该可以工作:
var myArr = new Array();
myArr["MyKey"] = { name: "myobject" };
$(this).data(value)
了吗?请参阅 http://api.jquery.com/data/ 和 http://api.jquery.com/jQuery.data/。 - Stefan