我有一个小页面,我出来和产生的要素之一是测试一些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