[英]CSS, if html is value, change color
對不起,不清楚,我的意思是這個。
當前在頁面加載時,我獲取具有特定ID的鏈接,檢查數據庫,然后將結果json返回鏈接。 所以本質上:
<a href="#" class="switcher" id="Site_Gallery-<?php echo $item->id; ?>">...loading....</a>
成為:
<a id="Site_Gallery-563" class="switcher" href="#">Enabled</a>
要么
<a id="Site_Gallery-563" class="switcher" href="#">Disabled</a>
我想做的是CSS,或者在ajax調用上(不理想)是查看該值,然后將鏈接顏色設置為綠色或紅色。
我在CSS中發現可能要做的事
.switcher='Enabled' {
color: green;
} .switch='Disabled' {
color: red;
}
有什么技巧可以做到這一點嗎? ps感謝您到目前為止的回答
相當確定您不能使用直接CSS檢查元素的值。 在jQuery中,它看起來像:
$(function(){
$(".switcher").each(function(){
if ($(this).text() == "Enabled"){
$(this).addClass("enabled");
} else {
$(this).removeClass("enabled");
}
});
});
然后在CSS中,您只需查找“已啟用”類與“裸”切換器類即可:
.switcher{
color:red;
}
.switcher.enabled{
color:green;
}
val = $('#toggleElement').val()
if(val!==''){
$('#toggleElement').css('color','green')
}
也許
$('a[enabled]').css('color', 'green');
是朝着正確方向邁出的一步,或者
$('a[enabled=true]').css('color', 'green');
您可能正在尋找:active
和:focus
偽選擇器。
嘗試這個:
$('a#id').change(function() {
$(this).css('color', 'green');
});
但這是行不通的,因為您不能“更改”超鏈接html,除非沒有其他腳本。 功能change
旨在與文本輸入(如表格中的輸入)一起使用
希望我有所幫助。
編輯:剛得到您的意思(我認為)。 如果啟用,則表示鼠標懸停在鏈接上時,css偽類:hover
可以很好地實現此目的。 在Google上檢查,您將獲得大量結果
一些情況
如果enabled
,則表示
a#id:hover{...}
a#id:active{...}
有關如何使用CSS設置鏈接樣式的頁面: http : //www.echoecho.com/csslinks.htm
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.