我有一個小頁面,我出來和產生的要素之一是測試一些jQuery的:.addClass和.removeClass不點火
<i class="fa fa-arrow-up personstatus" id="status.3140" style="color: #00ff00;" aria-hidden="true"></i>
我使用jQuery做一些修改:
$('.personstatus')
.click(function() {
var color = $(this).css("color");
var personId = $(this).attr('id').replace('status.', '');
$.get('changestatus/' + personId,
function(response) {
if (color == 'rgb(0, 255, 0)') {
alert('Down');
$('#status.3140').removeClass('fa-arrow-up');
$('#status.3140').addClass('fa-arrow-down');
$('#status.3140').css('color', '#ff0000');
} else {
alert('Up');
$('#status.' + personId).removeClass('fa-arrow-down');
$('#status.' + personId).addClass('fa-arrow-up');
$('#status.' + personId).css("color", "#00ff00");
}
alert('Finished');
});
});
它擊中警戒線爲我所期望的,但它不是應用.removeClass
.addClass
或.css
的。
我的jQuery代碼另一部分,在那裏這些優良的工作:
$('.showdetails')
.click(function() {
var personId = $(this).attr('id');
document.getElementById('currentid').innerHTML = personId;
$.get('loadperson/basic/' + personId,
function(response) {
document.getElementById('persondetails_table').innerHTML = response;
$('.tab').removeClass('active');
$('#persondetails_basictab').addClass('active');
$('#person_details')
.lightbox_me({
centered: true
});
});
});
我缺少什麼?
如何有人點擊隱藏的元素? – depperm
@depperm - 它不是一個隱藏的元素,它是一個字體真棒圖標 –
您應該嘗試使用斷點或調試器語句來代替警報。然後,您可以查看那些正在嘗試操作的DOM值,看看它們是否實際可用。我的猜測是你的替換字符串可能是罪魁禍首。 – Swordfish0321