这是我的代码片段:
$('.content .form-submit').each(function(index) {
var id = $(this).attr('id');
var selector = "#" + id;
}
上面的变量出来就好了。他们返回 ajax-comments-submit-398 #ajax-comments-submit-398 (或页面上碰巧出现的任何表单编号)就好了。问题是我需要将结果动态传递给以下对象(代替下面的 [ID] 和 [SELECTOR]。
var obj3 = {
"ahah": {
[ID]: {
"url": "/ajax_comments/js",
"event": "click",
"keypress": null,
"wrapper": "comment-form-content",
"selector": [SELECTOR],
"effect": "ajaxCommentsSubmit",
"method": "before",
"progress": {
"type": "1bar",
"message": "Please wait..."
},
"button": {
"op": "Save"
}
}
}
}
我试过了
var obj3 = {
"ahah": {
id: {
"url": "/ajax_comments/js",
"event": "click",
"keypress": null,
"wrapper": "comment-form-content",
"selector": selector,
"effect": "ajaxCommentsSubmit",
"method": "before",
"progress": {
"type": "1bar",
"message": "Please wait..."
},
"button": {
"op": "Save"
}
}
}
}
但该对象从字面上读取“选择器”和“id”,而不是我想要传递的变量(ajax-comments-submit-398)
我将如何做到这一点?