我想将 ajax 回调函数中的下拉值作为参数 ($user_id,$selected) onchange 传递,但我没有在这个 ajax 回调函数 onchange 事件中获得 $selected 值**
问问题
1959 次
2 回答
0
$form['changethis'] = array(
'#type' => 'select',
'#title' => t('Rece/Paid'),
'#description' => t('See Records'),
'#options' => $options,
'#default_value' => $selected,
'#ajax' => array(
'callback' => 'ajax_callback',
'wrapper' => 'replace_textfield_div',
'event' => 'change',
'progress' => array( 'type' => 'none', ),
),
);
以上添加是为了便于阅读。
您的选择是否发布了某些内容但没有得到结果?或者它根本没有发布任何东西?
您的代码看起来不错,但您确定要使用 ajax 回调“ajax_callback”吗?这不应该是您自己的返回部分表单的函数吗?
另外,我不确定'progress' => array( 'type' => 'none', ),
文档说只有“throbber”和“bar”是有效的。
尝试这样的事情
function my_module_create_form($form, $form_state){
// check form_state here to see if the form has been submitted
// via ajax and change if needed.
$options = array(0, 1, 2);
$selected = 0;
$form = array();
$form['changethis'] = array(
'#type' => 'select',
'#title' => t('Rece/Paid'),
'#description' => t('See Records'),
'#options' => $options,
'#default_value' => $selected,
'#ajax' => array(
'callback' => 'my_module_ajax_callback',
'wrapper' => 'replace_textfield_div',
'event' => 'change',
),
);
return $form;
}
function my_module_ajax_callback($form, $form_state) {
// because this is called from change event on select,
// it wont rebuild the form (call my_module_create_form).
// If you want it to you have to set $form_state['rebuild']
// (or it may be $form['rebuild'], I can't remember which one.)
// return form part
return $form['changethis'];
}
于 2013-01-17T09:08:17.180 回答
0
使用 jQuery:$("#yourdropdownid option:selected").text();
于 2013-01-17T07:46:17.453 回答