2017-09-11 13 views
0

私は次のフォームコードを持っています。フォームの提出を防ぎ、カスタムイベントを発生させなければなりません。私はまた、そのイベントをトリガする機能をサブミットし、falseを返すようにJavaScriptを書いています。間違っていると助けてください。javascriptカスタムイベントファイヤーを返す関数からの呼び出し

フォームのHTML:

<form class="form-inline" action="" name="filterform"> 
     <div class="row"> 
     <?php foreach($formatted_post_type as $filters){?> 
     <div class="checkbox"> 
      <label class="checkbox-inline" style="line-height:40px;"> 
      <input type="checkbox" name="filters[posttype][]" value="<?php echo $filters['slug']?>" onclick="refresh_posttypes();" /> 
      <?php echo $filters['name']?></label> 
     </div> 
     <?php }?> 
     </div> 
     <div class="row"> 
     <div class="col-md-12"> 
      <input type="submit" class="btn btn-primary btn-sm" value="Apply"> 
     </div> 
     </div> 
    </form> 

コードのjavascript:

jQuery(document).ready(function(){ 
    jQuery('form[name="filterform"]').on('submit', function(e){ 
     jQuery(document).triggerHandler('favorites-update-all-lists', function(e){ 
      e.preventDefault(); 
    }); 
    return false; 
    }); 
    }); 

答えて

0

右提出ハンドラ後e.preventDefault();を移動してみてください:

jQuery(document).ready(function(){ 
    jQuery('form[name="filterform"]').on('submit', function(e){ 
     e.preventDefault(); 

     jQuery(document).triggerHandler('favorites-update-all-lists', function(e){ 

     }); 
    return false; 
    }); 
    }); 
+0

感謝。それは作品です –

0

あなたは両方の匿名関数で電子を使用しているこの

$(function() { 

    $('form[name="filterform"]').on('submit', function(e) { 
     $(document).triggerHandler('favorites-update-all-lists', function() { 
      e.preventDefault(); 
     }); 
    }); 

}); 

てみてください

関連する問題