need to creat variable variable in Javascript--not an array
I'm needing to call a plugin that uses a var to work it's self. but I can't get the var cause that can change so... this is what I was trying to do.
var selection = $(".view-your-rescues .cms_textarea,.post-a-rescue .cms_textarea,.edit-accoun开发者_运维技巧t-details .cms_textarea");
if(selection.length > 0 ) {
selection
.css({"height":"100","width":"500"})
.each(function(i) {
var eval("hb"+i ) = $(this).htmlbox({
toolbars:[[
"separator","bold","italic","underline","strike","sup","sub",
"separator","justify","left","center","right",
"separator","ol","ul","indent","outdent"
]],
icons:"silk",
skin:"red",
idir:"/uploads/htmlbox/",
about:false
});
});
}
So that is based on this http://htmlbox.remiya.com/cms/demo/iconsets-demo/ where you'll see that that in order to do two you need to have the different vars.
The important part is
.each(function(i){
var eval("hb"+i )= $(this).htmlbox({
I tried the eval.. but I don't like that idea and it don't work anyway... any ideas?
EDIT: I can't do var eval("hb"+i )= $(this) and if I go
eval("hb"+i )= $(this)
I just get "hb0 is not defined"
Hope that makes sense. Thank you for the help. Cheers -Jeremy
Having var
there won't help much at all -- even if it worked, it'd put the variables out of any useful scope in this case.
Globals are actually usually members of window
, so what you could do, if you're ok with globals, is something like
.each(function(i) {
window["hb"+i] = $(this).htmlbox({ /* your params */ });
});
精彩评论