Jquery 如何制作<;选项>;使用“附加”插入时选择?
我正在使用ajax添加一个Jquery 如何制作<;选项>;使用“附加”插入时选择?,jquery,Jquery,我正在使用ajax添加一个,并在成功时附加它: success: function(data) { var newdata = data.replace(/['"]+/g, ''); jQuery('#argomenti').append('<option value="">'+newdata+'</option>'); } 成功:函数(数据){ var newdata=data.replace(/['“]+/g'); jQuer
,并在成功时附加它:
success: function(data) {
var newdata = data.replace(/['"]+/g, '');
jQuery('#argomenti').append('<option value="">'+newdata+'</option>');
}
成功:函数(数据){
var newdata=data.replace(/['“]+/g');
jQuery('#argomenti').append(''+newdata+'');
}
但我如何使它成为选中的,因为我将在其中有许多其他标记和值
类似于
$('#argomenti').val(newdata).prop('selected',true);
您只需设置'selected'属性,如下所示:
jQuery('#argomenti').append('<option value="" selected="selected">'+newdata+'</option>');
jQuery('#argomenti').append(''+newdata+'');
我建议:
// creating the element, passing an object of
// properties, and values, to set to that object:
$('<option>', {
'selected': true,
'text': newdata})
// appending the created element to its parent element:
.appendTo('#argomenti');
//创建元素,传递
//要设置为该对象的属性和值:
$('', {
“已选择”:true,
“文本”:newdata})
//将创建的元素附加到其父元素:
.appendTo(“#argomenti”);
哦,对了,我明白了,我想我必须将该值设置为