使用jQuery创建新的选择下拉对象
我正在尝试创建一个select(使用jQuery创建新的选择下拉对象,jquery,html,select,drop-down-menu,Jquery,Html,Select,Drop Down Menu,我正在尝试创建一个select(使用 var photos=[''u DSC0153.jpg','u DSC0154.jpg']; 变量下拉列表=$(“”{ id:'选择文件' }); //重复这些照片 //创建选项 //并将其附加到select 对于(i=0;i
使用
var photos=[''u DSC0153.jpg','u DSC0154.jpg'];
变量下拉列表=$(“”{
id:'选择文件'
});
//重复这些照片
//创建选项
//并将其附加到select
对于(i=0;i
我建议如下:
var photos = [
'_DSC0153.jpg',
'_DSC0154.jpg'
];
// creating the <select> element:
$('<select>', {
// setting its 'id' property/attribute:
'id' : 'selectfile'
// in order to append nodes (rather than a string of HTML),
// we use the append() method:
}).append(function () {
// using Array.prototype.map() to iterate
// over the given (photos) array, creating a
// a new array. Using the anonymous function's
// arguments (el: the array-element itself,
// i: the index of the array-element) to
// create new <option> elements using the
// new Option() Constructor; setting
// its text (to the filename, el) and
// value (to the index, i):
return photos.map(function(el,i){
return new Option(el, i);
});
// appending the <select> to the <body>:
}).appendTo('body');
var照片=[
"DSC0153.jpg",,
"DSC0154.jpg"
];
//创建元素:
$('', {
//设置其“id”属性/属性:
“id”:“selectfile”
//为了附加节点(而不是一个HTML字符串),
//我们使用append()方法:
}).append(函数(){
//使用Array.prototype.map()进行迭代
//在给定的(照片)阵列上,创建
//新数组。使用匿名函数的
//参数(el:数组元素本身,
//i:数组元素的索引)到
//使用
//新选项()构造函数;设置
//它的文本(到文件名el)和
//值(对于索引,i):
返回照片。地图(功能(el,i){
返回新选项(el,i);
});
//将以下内容附加到:
}).附于(“主体”);
var照片=[
"DSC0153.jpg",,
"DSC0154.jpg"
];
$('', {
“id”:“selectfile”
}).append(函数(){
返回照片。地图(功能(el,i){
返回新选项(el,i);
});
}).appendTo('body');
var photos = [
'_DSC0153.jpg',
'_DSC0154.jpg'
];
var dropdown = $("<select>", {
id: 'selectfile',
for (i = 0; i < files.length; i++) {
option: { value: i, text: photos[i] }
}
});
dropdown.appendTo( $('#gallery') );
var photos = ['_DSC0153.jpg', '_DSC0154.jpg'];
var dropdown = $("<select>", {
id: 'selectfile'
});
//Iterate the photos
//Create option
//and append it to select
for (i = 0; i < photos.length; i++) {
var option = $('<option></option>', {
value: i,
text: photos[i]
});
dropdown.append(option);
}
dropdown.appendTo('#gallery');
var photos = [
'_DSC0153.jpg',
'_DSC0154.jpg'
];
// creating the <select> element:
$('<select>', {
// setting its 'id' property/attribute:
'id' : 'selectfile'
// in order to append nodes (rather than a string of HTML),
// we use the append() method:
}).append(function () {
// using Array.prototype.map() to iterate
// over the given (photos) array, creating a
// a new array. Using the anonymous function's
// arguments (el: the array-element itself,
// i: the index of the array-element) to
// create new <option> elements using the
// new Option() Constructor; setting
// its text (to the filename, el) and
// value (to the index, i):
return photos.map(function(el,i){
return new Option(el, i);
});
// appending the <select> to the <body>:
}).appendTo('body');