Jquery 故障设置';动态';变量
我想动态设置变量名称,我一直在尝试:Jquery 故障设置';动态';变量,jquery,variables,Jquery,Variables,我想动态设置变量名称,我一直在尝试: var iframes = $('iframe').filter(function (index) { return index == 0 || $(this).attr("current") == "no"; }) if(iframes.length >0){ //if one of the iframes hasnt got current set as current,
var iframes = $('iframe').filter(function (index) {
return index == 0 || $(this).attr("current") == "no";
})
if(iframes.length >0){ //if one of the iframes hasnt got current set as current, use it
var theSuffix = iframes.attr('id').split('_').pop();
window['thisPreview'+theSuffix] = $fi.prev(".image-preview");
$hidden.closest(".file-upload-form").find(".variable-hidden").attr('value',theSuffix);
}
其中我需要一个名为“thisPreview”的变量,然后是一个数字,它将是匹配div的id,或者是变量“theSuffix”(变量也需要是全局变量)
我怎样才能做到这一点呢?不要让变量的末尾有一个共同的前缀和数字。只需使用一个对象:
var thisPreview = {};
...
thisPreview[theSuffix] = $fi.prev(".image-preview");
你为什么想要那样的东西?我将创建一个对象
var thisPreview
,并为每个uffix