jquery - css改变jquery语法

标签 jquery css

对于我的网站,我尝试使用从向下箭头变为向上箭头的箭头。我想使用 css 更改,因为我觉得这是最简单的方法。我的代码是

$(".first1").on('click', 
  function () {
$('.arrow-down').css({"display" : "none"});
    $('.arrow-up').css({"display" : "inline"});
  },
  function () {
    $('.arrow-down').css({"display" : "inline"});
    $('.arrow-up').css({"display" : "none"});
  });
$(".last1").on('click', 
  function () {
    $('.arrow-down').css({"display" : "none"});
    $('.arrow-up').css({"display" : "inline"});
  },
  function () {
    $('.arrow-down').css({"display" : "inline"});
    $('.arrow-up').css({"display" : "none"});
  });

.arrow-up {
    width: 0; 
    height: 0; 
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 10px solid #FDFECD;
    display: none;
}
.arrow-down {
    width: 0; 
    height: 0; 
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-top: 10px solid #FDFECD;
    display: inline;
}

最佳答案

您不能像这样绑定(bind)两个点击事件。相反,您必须自己管理“点击状态”:

$(".first1, .last1").data('active', false);

$(".first1, .last1").on('click', function () {
   if ($(this).data('active')) {
      $('.arrow-down').css({"display" : "none"});
      $('.arrow-up').css({"display" : "inline"});
      $(this).data('active', false);
   }
   else {
     $('.arrow-down').css({"display" : "inline"});
     $('.arrow-up').css({"display" : "none"});
     $(this).data('active', true);
   }
});

关于jquery - css改变jquery语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14574431/

相关文章:

javascript - 如何附加用户输入?查询

html - 如何在 CSS 中塑造边框尖峰

css3 适用于 jfiddle 但不适用于 IE

javascript - Angular 动画

jquery - 可自定义的 jquery 掩码

javascript - jquery ajax 关闭后发布

javascript - 在 FullCalendar 中传递动态数据时出错

html - 居中列出的右对齐段落

html - Opencart 背景图像/颜色错误

html - 使用 High Charts 和 Bootstrap 3 的响应式折线图