2015-10-07 65 views
0
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女衬衫面料”。 if有什么不对?我可以在这里使用哪些替代方案?Jquery如果条件验证

+8

一些属性'if'是不是循环 –

+1

试text.trim() – guramidev

+2

'“外循环文字是” +文字'在​​'is'后面没有空格,''外面的文字是Unstiched Blouse Fabric“。 – Andrei

回答

0

看起来你有空间之前

“Unstiched衬衫面料”

确保你要么(前空间)与相同值进行比较或做出微调。

+0

text.trim();做了这份工作。谢谢。 – amitshree

0

我觉得比较字符串是坏主意你为什么不这样设置

<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()); 
}