js(jquery)的on绑定点击事件执行两次的解决办法—不是事件绑定而是事件冒泡

阻止冒泡的方法并不止 return false 这一种,还有event.stopPropagation(),这两种方法是有区别的,简单来说:
event.stopPropagation()会阻止事件往上冒泡,但是并不阻止事件本身;
return false 则是既阻止了事件往上冒泡又阻止了事件本身。

修改前

    $(".project_select").change(function () {

        var checkText=$(".project_select").find("option:selected").text();
        //alert(checkText);

        if (checkText == '请选择') {
            return false;
        }




       });

 

修改后

 

    $(".project_select").unbind('change').change(function () {

        var checkText=$(".project_select").find("option:selected").text();
        //alert(checkText);

        if (checkText == '请选择') {
            return false;
        }

       });

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案