gpt4 book ai didi

javascript - jQuery val() 在 IE 中无法用于动态添加的选项

转载 作者:搜寻专家 更新时间:2023-11-01 04:38:01 27 4
gpt4 key购买 nike

我正在通过 jQuery ajax 方法为我的下拉菜单生成选项,并通过 db 填充它。

$.ajax({
type: "POST",
url: pageUrl + '/FillAssignee',
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
for (var i = 0; i < response.d.length; i++) {
$('#SelectAssignee').append($("<option></option>").val(response.d[i]['Value']).html(response.d[i]['Text']));
}
if (response.d.length > 0)
{
$('#SelectAssignee>option:eq(1)').attr('selected', true);
alert($('#SelectAssignee').val()); //this line giving me correct value but value not showing in dropdown as selected in ie
}
}
});

它工作正常。唯一的问题是第一个值在 IE 上默认没有被选中。所以为此我使用了很多选项

1. $('#SelectAssignee').val();
2. $('#SelectAssignee option:first').attr('selected','selected');
3. $('#SelectAssignee option:first').prop('selected',true);

我怎样才能让它工作?

最佳答案

尝试这样的事情

 var selObj = document.getElementById('SelectAssignee');
selObj.selectedIndex = 0;

关于javascript - jQuery val() 在 IE 中无法用于动态添加的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13263764/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com