2013-03-22 56 views
0

讓利串說,我有這樣的:JavaScript來利用價值得到使用的.html作爲條件

alert($('#child_check').html()); 
      if($('#child_check').html() != "Select..." || $('.funnel_items').val() == "5" || $('.funnel_items_sub').val() != "Select..."){ 
       return true; 
      }else{ 
       alert("No Sub category selected!"); 
       return false; 
      } 

的html的回報:

  No available selection for this action. 

我將如何能夠檢查是否.html等於輸入的字符串,因爲如果我警告$('#test').html()它包含該字符串,但條件不返回true,所以我想知道這個代碼有什麼問題?

也真的不可能使用html的值作爲字符串比較的CODI

謝謝

+1

從'html的返回值進行比較()'到另一個字符串應該正常工作。問題很可能是您的條件錯誤,或者.html()的返回結果實際上不匹配。沒有看到HTML,這是不可能說的。 – 2013-03-22 22:26:56

+0

添加了由.html返回的值 – magicianiam 2013-03-22 22:34:25

回答

1

我覺得你是想看看是否html的結果()「包含」另一串。

http://jsfiddle.net/XRWHF/

var haystack = $('#foo').html(); 
var needle = 'No available selection for this action.'; 
if (haystack.indexOf(needle) !== -1) { // If needle is inside haystack 
    return true; 
} else { 
    return false; 
} 
+0

是的即時通訊嘗試查找.html是否包含字符串「此操作沒有可用的選擇」。 – magicianiam 2013-03-22 22:46:28

+0

好的,爲您編輯。 – 2013-03-22 22:53:44