Jquery addOption Problems
val1 = "1";
text1 = "the text";
var myOptions = {
val1 : text1
}
$("#map_element_map_element_folder_id").addOption(myOptio开发者_如何转开发ns, true);
i have this script. but when i run it option which added to select box is
text = "the text" <- this one is correct
value = 'val1' <- its not supposed to be like this, it supposed fill with "1", because i declare val1 = "1" in top of script
anyone have idea what happen in here?
The way you are defining an object, you may expect var1 to set the key as the value you defined for the var1 variable. However to do dynamic object key assignment, you have to use the bracket style:
var myOptions = {};
myOptions[var1] = text1;
var myOptions = {
val1: val1,
text1:text1
};
精彩评论