【问题标题】:Set default value ACF select设置默认值 ACF 选择
【发布时间】:2017-12-19 22:22:37
【问题描述】:

是否可以在事件的多选(发布对象源)中设置默认值(例如 onclick 一个 js 函数计算一个值。该值是设置为选中的选项)?

我使用 acf.add_action('ready', .... 来获取设置为选中的值。它有效。 但我现在不知道如何设置它。

提前致谢。

【问题讨论】:

    标签: select advanced-custom-fields


    【解决方案1】:
    $member_id = $view->member_id; // variable in script to be passed coming from object (could be any variable.)
    add_filter('acf/load_field/name=visit_name',
         function($field) use ($member_id) { 
          /* the variable after 'use' ($member_id) indicates that it is the one to 'use' from the main script.  $field is coming from 'acf/load_field'.  */
         $field['default_value'] = $member_id;
         return $field;
     }
    );
    

    【讨论】:

    • 如果你来巴尔的摩,前两种啤酒都在我身上。
    【解决方案2】:

    你可以这样设置:

    document.getElementById('id_of_your_select_element').value=value_of_option_to_select;
    

    在这里找到它: https://stackoverflow.com/a/10911660

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      • 2014-02-16
      • 2017-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多