【发布时间】:2017-03-02 10:55:07
【问题描述】:
我正在使用 Drupal 7 Form Api 构建带有选择元素的自定义表单。我正在为其附加#ajax 回调,它将在更改事件时触发。
$form['landing']['country'] = array(
'#type' => 'select',
'#options' => array(),
'#attributes' => array('class' => array('landing-country-list')),
'#validated' => TRUE,
'#prefix' => '<div id="landing-countries" class="hide">',
'#suffix' => '</div>',
'#title' => 'Select country',
'#ajax' => array(
'wrapper' => 'landing-cities',
'callback' => 'get_cities',
'event' => 'change',
'effect' => 'none',
'method' => 'replace'
),
);
但问题是它阻止了 js 中相同选择的自定义更改功能。在这个函数中,我想获得选定的选项值。所以这不会触发:
$('body').on('change', 'select.landing-country-list', function() {
optval = $(this).find('option:selected').val();
});
此代码在文件中,我将其包含在 $form 中:
$form['#attached']['js'] = array(
'https://code.jquery.com/jquery-2.2.4.min.js',
drupal_get_path('module', 'landing') . '/landing.js',
);
提前感谢您的帮助!
【问题讨论】:
标签: javascript jquery drupal drupal-7