gpt4 book ai didi

javascript - 两个字符串的比较在脚本中不起作用

转载 作者:行者123 更新时间:2023-11-28 15:08:21 25 4
gpt4 key购买 nike

实际上,在我的函数中,我必须比较两个字符串,我通过数据库获取的一个字符串并与 null 字符串进行比较,但它不起作用。这是我的代码:

   order.items.forEach(function(entry) {
result += '<tr>'
+ '<td>'+'<font size=2>'+ a++ + '</font>'+ '</td>'
+ '<td>' +'<font size=2>'+ entry.title + '</font>'+ '</td>'
+ '<td>' +'<font size=2>'+ entry.quantity + '</font>'+'</td>'
if(entry.personalization == 'null') //here is the problem
+ '<td>' +'<font size=2>'+ 'No Personalization' + '</font>'+'</td>'
else
+ '<td>' +'<font size=2>'+ entry.personalization + '</font>'+'</td>'


+ '</tr>';
})

result +='</table>';

$('.modal-body').html(result);

最佳答案

使用console.log(entry.personalization)检查值。

达拉的回答应该有效......

我也用它来进行 null 检查。

(!entry.personalization)  

或者尝试

(entry.personalization != "")

关于javascript - 两个字符串的比较在脚本中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37879732/

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