【发布时间】:2013-10-01 04:24:36
【问题描述】:
这些是我的代码的摘录
<button>Hook It!</button>
还有一点JQuery
$("ul li .tag_detail button").on('click', function() {
console.log($(this).html());
if ($(this).html() == 'Hook It!') {
$(this).html('Unhook!');
}
if ($(this).html() == 'Unhook!') {
$(this).html('Hook It!');
}
});
现在,如您所见,我想要一个切换效果,即当我点击按钮时,它应该在 Hook It 之间切换!并解开!
问题出在这里
if($(this).html() == 'Hook It!')
在控制台日志打印 Hook It 时,此条件永远不会通过!
console.log($(this).html());
【问题讨论】:
-
你应该使用
else if,把else放在第二个if之前 -
Button text toggle in jquery 的可能重复项
标签: javascript jquery html dom