2017-02-21 22 views
1

我有三個jQuery函數,我需要調用第三個函數中的第二個函數。前兩個工作正常,但第三個函數應該追加一個div正好低於前一個函數的結果,我想再次運行第二個函數,從而創建一個列表。我是jQuery的新手。請參閱HTML和下面的Javascript代碼:在另一個jQuery函數內調用jquery功能

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>

回答

0

不知道這個回答你的問題,但我會試試看。您可以觸發點擊事件是這樣的:

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

不工作,但我認爲其原因是保存按鈕改變了位置。不管怎麼說,多謝拉 :) – dpr

相關問題