没有警报,jQuery无法正常工作

时间:2017-04-17 05:21:57

标签: jquery alert

我有jQuery代码,如果没有alert语句就无法运行。 整个javascript文件是
codepen.io/smarty_tech/pen/gWpKjE

(function($) {
  jQuery.fn.lightTabs = function(options) {
    var createTabs = function() {
        tabs = this;
      i = 0;

      showPage = function(i) {
        $(tabs).children("div").children("div").hide();
        $(tabs).children("div").children("div").eq(i).show();
        $(tabs).children("select").children("option").removeClass("current");
        $(tabs).children("select").children("option").eq(i).addClass("current");
      }

      showPage2 = function(i) {
        $(tabs).children("div").children("div").hide();
        $(tabs).children("div").children("div").eq(i).show();
        clasw = '.re-compare-wrap-' + i;
        $(clasw).css("display", "block");
        $(clasw).css("display", "block");
      }

      showPage(0);

      datap = $('#re-compare-bar-tabs').children("select").children("option:selected").attr("data-page");

      <!-- $(tabs).children("select").children("option").removeClass("current");  -->

      $('.re-compare-wrap').css("display", "none");

      clas = '.re-compare-wrap-' + datap;
      $(clas).css("display", "block");

      function ret(dt) {
        return dt.attr('data-comparing');
      }

      function abc() {
        var dt = $("#re-compare-bar-tabs select option:first");
        va1 = ret(dt);
        alert(va1);
        if (typeof va1 !== typeof undefined && va1 !== false) {
          alert('hi');
          words1 = va1.split(",");
          text1 = $(this).html();
          pos11 = text1.indexOf("(");
          pos21 = text1.indexOf(")");
          $(this).text(text1.substring(0, pos11 + 1) + words1.length + text1.substring(pos21));

        }

        $("#re-compare-bar-tabs select > option").each(function() {

          va = ret($(this));
          alert(va);
          if (typeof va !== typeof undefined && va !== false) {

            words = va.split(",");
            alert(words.length);
            text = $(this).html();
            pos1 = text.indexOf("(");
            pos2 = text.indexOf(")");
            $(this).text(text.substring(0, pos1 + 1) + words.length + text.substring(pos2));

          }
        });
      }

      abc();

      $(tabs).children("select").children("option").each(function(index, element) {
        $(element).attr("data-id", i);
        i++;
      });
      $(tabs).children("select").change(function() {

        var element = $(this).find('option:selected');
        showPage(parseInt(element.attr("data-id")));
      });
    };
    return this.each(createTabs);
  };
})(jQuery);

从功能返回代码无法在没有警报的情况下工作。我试过https://www.sitepoint.com/community/t/script-works-only-when-alert-is-called/2803/7但没有运气。

1 个答案:

答案 0 :(得分:0)

您可以使用import React from 'react' class App extends React.Component { constructor(props){ super(props); this._myMethod=this._myMethod.bind(this); } componentWillMount() { this._myMethod(this.props); } componentWillReceiveProps(nextProps) { this._myMethod(nextProps); } _myMethod(props){ console.log(props); } render() { return( <div> <h>hiiiiii</h1> </div> )} } 代替创建延迟警报。

setTimeout