如何改进 jquery 中的点击/切换功能?
$('.tabs a ').click(function () {
var a = $(this).attr('href');
if (a == '#tab-1') {
$('.btn-buy').hide();
$('.btn-sell').show();
} else {
$('.btn-sell').hide();
$('.btn-buy').show();
}
return false;
});
...它可以工作,但是代码很丑,行太多。还能再减少吗?
预先感谢您的帮助!
$('.tabs a ').click(function () {
var a = $(this).attr('href');
if (a == '#tab-1') {
$('.btn-buy').hide();
$('.btn-sell').show();
} else {
$('.btn-sell').hide();
$('.btn-buy').show();
}
return false;
});
... it works, but the code is ugly, too many lines. Can it be reduced any further?
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以只使用切换:
这会假设它们最初以正确的状态开始......
You could just use toggle:
This would assume they start out in their correct state initially...