[英]Having trouble with jquery if statement with css property
function toggleLinkSelection(link){
if($(link).css('border-top-color') == 'red'){
$(link).css({'border-top-color': 'transparent'});
} else {
$("div[id$='OptionsLink']").css({'border-top-color': 'transparent'});
$(link).css({'border-top-color': 'red'});
}
}
我在if陳述中做錯什么了嗎? 它永遠不會測試正確。 在瀏覽器中,我檢查項目,它應該測試為true。 我嘗試用#F00和#FF0000替換紅色,但這沒有幫助。 鏈接變量= #testID謝謝。
顏色以rgb返回
$(link).css('border-top-color')==='rgb(255, 0, 0)'
ps:當您知道輸出將是什么時,請始終使用3等於,否則可能會遇到一些令人討厭的驚喜
編輯:由JesseB 演示 (請參閱下面的帖子)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.