在另一个jquery函数

时间:2017-02-21 19:53:41

标签: jquery html

我有三个jQuery函数,我需要调用第三个函数。前两个工作正常,但第三个函数应该在函数的前一个结果的正下方追加div,我想再次运行第二个函数,从而制作一个列表。我是jQuery的新手。请参阅下面的HTML和Javascript代码:



jQuery(document).ready(function() {
  $('.add-doc').click(function() {
    $(this).parent(".no-doc-para").hide();
    $(this).parent().siblings(".doc-list").show();
  });

  $('.save').click(function() {
    $(this).parent().parent(".main-section").hide();
    $(this).parent().parent().siblings(".some-doc").show();
  });

  $('.add-plus').click(function() {
    var doc = $(this).parent().siblings().children(".doc-list");

    if ($(this).parent().siblings().children(".no-doc-para").is(':visible') || $(this).parent().siblings().children(".doc-list").is(':visible')) {
      $(this).attr('disabled', 'disabled');
    } else if ($(this).parent().siblings(".some-doc").is(':visible')) {
      $(this).parent().siblings(".some-doc").append(doc);
      savedoc();
    }
  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="start">
  <div class="row">
    <div class="col-sm-1">
      <h2 class="page-title">Start</h2>
    </div>
    <div class="btn-group col-sm-1 pull-right add-plus">
      <button type="button" class="btn btn-custom dropdown-toggle waves-effect waves-light" data-toggle="dropdown" aria-expanded="false">
      <i class="fa fa-plus"></i>
      </button>
    </div>
  </div>
  <hr>
  <div class="main-section">
    <div class="row no-doc-para">
      <div class="col-sm-2 m-b-30">
        <p>You currently have no documents in this section.</p>
      </div>
      <div class="col-sm-1 add-doc">
        <div class="form-group">
          {!! Form::button("Add Document", ["class" => "btn btn-primary waves-effect waves-light"]) !!}
        </div>
      </div>
    </div>
    <div class="row doc-list" style="display: none;">
      <div class="col-sm-2 m-b-30">
        <div class="form-group{{ $errors->has('opportunity') ? ' has-error has-feedback' : '' }}">
          {!! Form::select('Documents', ['Listing Agreement', 'Listing Agreement'], ["class" => "form-control validation-required ", "placeholder" => ""]) !!}
        </div>
      </div>
      <div class="col-sm-1 m-t-30 primary">
        <div class="form-group{{ $errors->has('price1') ? ' has-error has-feedback' : '' }}">
          {!! Form::text("days", old('days'), ["class" => "form-control validation-required form-position", "placeholder" => ""]) !!} days
        </div>
      </div>
      <div class="col-sm-2 m-b-30">
        <div class="form-group{{ $errors->has('price') ? ' has-error has-feedback' : '' }}">
          {{ Form::select('contract_days', ["before"=>"Before Contract","by" => "By Contract"],null, ["class" => "form-control validation-required input-filter"]) }}
        </div>
      </div>
      <div class="col-sm-1 save">
        <div class="form-group">
          {!! Form::button("Save", ["class" => "btn btn-primary waves-effect waves-light"]) !!}
        </div>
      </div>
    </div>
  </div>
  <div class="row some-doc" style="display: none;">
    <ul class="list">
      <div class="col-sm-3">
        <button type="button" class="btn btn-custom dropdown-toggle waves-effect waves-light" data-toggle="dropdown" aria-expanded="false">
          <i class="zmdi zmdi-collection-pdf"></i>
        </button> Some Document
      </div>
      <div class="col-sm-2 pull-right">
        20 days before...
        <button type="button" class="btn btn-custom dropdown-toggle waves-effect waves-light" data-toggle="dropdown" aria-expanded="false">
          <i class="zmdi zmdi-edit"></i>
        </button>
      </div>
    </ul>
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

不确定这会回答你的问题,但我会试一试。您可以触发点击事件,如下所示:

$('.add-doc').click();   // will execute the first 'function'
$('.save').click();      // will execute the second 'function'
$('.add-plus').click();  // will execute the third 'function'