douxia6554
2017-04-04 08:48
浏览 48
已采纳

使用jquery将类添加到ajax表单

help me please with my form. I have ajax form here https://dev.atdevside.com/jobs/ At left sidebar item work such as filter on click, how i can toggle class to element after click.

            jQuery(document).ready(function ($) {
                var container = $(".noo-main > .jobs");
                if (container.length) {
                    $("#filter_form").change( function (event) {
                        event.preventDefault();
                        var $form = $("#filter_form .form-control");
                        var data = $(this).serialize();
                        history.pushState(null, null, "?" + $form.serialize());
                        $.ajax({
                                url: "<?php echo admin_url('admin-ajax.php'); ?>",
                                data: data
                            })
                            .done(function (data) {
                                if (data !== "-1") {
                                    $(".noo-main").html(data);
                                    if ($('[data-paginate="loadmore"]').find(".loadmore-action").length) {
                                        $('[data-paginate="loadmore"]').each(function () {
                                            var $this = $(this);
                                            $this.nooLoadmore({
                                                navSelector: $this.find("div.pagination"),
                                                nextSelector: $this.find("div.pagination a.next"),
                                                itemSelector: "article.loadmore-item",
                                                finishedMsg: "<?php echo __('All jobs displayed', 'noo'); ?>"
                                            });
                                        });
                                    }
                                } else {
                                    location.reload();
                                }
                            })
                            .fail(function () {

                            })
                    });
                }
                $("#filter_form").submit(function () {
                    $(this).find("input[name='action']").remove();
                    $(this).find("input[name='_wp_http_referer']").remove();
                    $(this).find("input[name='live-search-nonce']").remove();

                    return true;
                });
            });

</div>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglong2856 2017-04-04 08:54
    已采纳

    You can try this.

    jQuery('.filter_by').on('click', function(){
      jQuery(this).addClass('hello');
    });
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题