0

我正在尝试将 SiteOrigin 的 Page Builder 集成到我的插件中。我通过此处siteorigin_panels_row_style_fields找到的过滤器在行样式下添加了一些自定义字段。自定义字段之一是选择。I would like fields to either be hidden or displayed when the select is at a certain value. 我已经根据文档使用操作将 Javascript 排入 Page Builder 队列,甚至使用一些测试代码添加了事件:siteorigin_panel_enqueue_admin_scriptspanelsopen

jQuery( document ).ready(function($) {
  $(document).on('panelsopen', function(e) {
    $('select[name="style[test_field]"]').bind('change', function (e) {
      if( $(this).val() == 'option1' ) {
        $('input[name="style[second_field]').hide(500);
        $('input[name="style[third_field]').show(500);
      } else {
        $('input[name="style[second_field]').show(500);
        $('input[name="style[third_field]').hide(500);
      }
    });
  });
});

但是,这似乎不起作用。任何帮助或想法如何解决这个问题将不胜感激!

4

1 回答 1

0

经过一些研究,我通过使用ajaxComplete()jQuery 中的函数来解决这个问题。这是它的工作原理:

$(function() {
  $(document).ajaxComplete(function() {

    $('select[name="style[test_field]"]').bind('change', function (e) {
      if( $(this).val() == 'option1' ) {
        $('input[name="style[second_field]').hide(500);
        $('input[name="style[third_field]').show(500);
      } else {
        $('input[name="style[second_field]').show(500);
        $('input[name="style[third_field]').hide(500);
      }
    });

  });
});

我希望这可以帮助任何试图实现类似目标的人。

于 2016-06-06T20:01:50.507 回答