Jquery if条件验证

Jquery if condition validation

本文关键字:验证 条件 if Jquery      更新时间:2023-09-26
var text = jQuery('#product-options-wrapper ul li:first label').text();
alert('text outside loop is' + text);
if(text == "Unstiched Blouse Fabric") {
alert('inside loop' + text);
}

使用上面的代码,我只得到警告消息打印"文本外循环isUnstiched衬衫面料"。如果有什么问题?在这里我可以使用哪些替代方案?

前面好像有空格

"未缝线衬衫面料"

请确保与相同的值进行比较(空格前)或进行修剪。

我觉得比较字符串是个坏主意为什么不设置一些属性呢

<label attribute="1">Unstiched Blouse Fabric</label>
var text = jQuery('#product-options-wrapper ul li:first label');
if($(text).prop("attribute") == 1) {
alert('inside condition' + $(text).text());
}