Jquery函数从点击开始,但我需要停止它

时间:2016-04-13 08:51:21

标签: javascript jquery html

我总是想知道onclick函数会启动javascript或jQuery,但它是如何停止的?最后,我在学习进度中面临着一个功能。你可以帮我找一个解决方案吗?

我想在另一个onclick上停止此功能:

function live_preview() {
        var icon = document.getElementById('LivePreIcon');

        if (icon.classList.contains('fa-eye-slash')) {
            icon.classList.remove('fa-eye-slash');
            icon.classList.add('fa-eye');
            $('#result').keyup(function () {
                $('#dialog').html($(this).val());
            });
            return;
        }
        if (icon.classList.contains('fa-eye')) {
            icon.classList.remove('fa-eye');
            icon.classList.add('fa-eye-slash');
            // Stop the jquery function here
            return;
        }

    }

1 个答案:

答案 0 :(得分:0)

var play=0;
function live_preview() {
            var icon = document.getElementById('LivePreIcon');
            var play;
            if(!play){
                    if (icon.classList.contains('fa-eye-slash')) {
                      icon.classList.remove('fa-eye-slash');
                      icon.classList.add('fa-eye');
                      $('#result').keyup(function () {
                          $('#dialog').html($(this).val());
                           play = 1;
                      });
                      return;
                    }
            }
            else{
                  if (icon.classList.contains('fa-eye')) {
                      icon.classList.remove('fa-eye');
                      icon.classList.add('fa-eye-slash');
                      play=0;
                      return false;
                      // Stop the jquery function here


                  }
           }
        }