嘿所有,我不明白为什么这似乎没有工作。 警报会弹出正确的ID,但removeClass似乎不会触发。 我在做什么错?用变量作为jQuery中的id来更改类?
function testClassSwitch(t_id) {
alert("Do things to a button with this ID: " + t_id);
$(t_id).removeClass("add-button");
}
谢谢!
嘿所有,我不明白为什么这似乎没有工作。 警报会弹出正确的ID,但removeClass似乎不会触发。 我在做什么错?用变量作为jQuery中的id来更改类?
function testClassSwitch(t_id) {
alert("Do things to a button with this ID: " + t_id);
$(t_id).removeClass("add-button");
}
谢谢!
请问您的t_id
有#
id selector吗?
哦,一个儿子! * facepalm *非常感谢,非常简单。 ; -/ – TwstdElf 2010-08-13 17:13:59
不用担心TwstdElf。这一个很容易错过:P。 – 2010-08-13 17:25:19
@TwstdElf - 同意,容易犯的错误:) – rosscj2533 2010-08-13 17:55:35
在ID前加#
这样
function testClassSwitch(t_id) {
alert("Do things to a button with this ID: " + t_id);
$('#' + t_id).removeClass("add-button");
}
适用于我:http://jsfiddle.net/sBJwJ/ – 2010-08-13 17:13:47
切换类使用toggleClass ...... – 2010-08-13 17:17:39