我通过在其元素中添加 show 来在引导程序中打开下拉菜单,效果很好。我也试图关闭其他打开的下拉菜单,这就是这个函数的作用。我的功能: function classremove() { var doesithavetheclass = $('div').hasClass('show'); if (doesithavetheclass == 'true') { $('div').removeClass('show'); }; return doesithavetheclass; };这if是不起作用的部分。if在作品中运行代码,并在 Chrome 控制台中定义变量可以正常工作,但是if即使在我使用 show 类打开下拉菜单定义变量之前,在 Chrome 控制台内部运行也不起作用。
1 回答

阿晨1998
TA贡献2037条经验 获得超6个赞
if 语句和大部分功能实际上是不需要的。您可以简化为仅删除该类。
function classremove() {
$('div').removeClass('show');
};
添加回答
举报
0/150
提交
取消