gpt4 book ai didi

javascript - 如何根据id向列表框添加星号

转载 作者:行者123 更新时间:2023-11-30 09:13:35 25 4
gpt4 key购买 nike

在我的 Asp Web 应用程序中,我使用 JSON 数据填充列表框。

我的部分JSON如下,

[  
{
"UserId":10259,
"FullName":"jhno doil",
"BID":""
},
{
"UserId":10405,
"FullName":"Adam mark",
"BID":"10261"
},
{
"UserId":16224,
"FullName":"silvester",
"BID":""
},
{
"UserId":10416,
"FullName":"Arnetta Chatcho",
"BID":"1"
},
{
"UserId":10244,
"FullName":"Ashanti Bueti",
"BID":"1000"
}
]

使用上面的 JSON 我像这样填充列表框,

function GetSupervisorComplete(result, status) {
"use strict";
var data = jQuery.parseJSON(result.d);
var lstsupervisor = $("[id*=lbSupervisor]");
lstsupervisor.empty();
$.each(data, function () {

lstsupervisor.append($("<option></option>").val(this['UserId']).html(this['FullName']));
});
}

如果 BID = "",如何将 astric mark(*) 添加到选项中?如下图所示。当我单击列表中的选项时,星号 * 无法显示在占位符中。如何将 * 添加到列表中?

enter image description here

最佳答案

具有基本的三元运算。像下面这样修改最后一行应该可以解决问题。

lstsupervisor.append($("<option></option>").val(this['UserId']).html(this['FullName'] + (this['BID'] === '' ? '*' : '')));

关于javascript - 如何根据id向列表框添加星号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56769575/

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