Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何制作<;选项>;使用“附加”插入时选择?_Jquery - Fatal编程技术网

Jquery 如何制作<;选项>;使用“附加”插入时选择?

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

我正在使用ajax添加一个
,并在成功时附加它:

    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”);

哦,对了,我明白了,我想我必须将该值设置为