Drupal 7 开发内部培训资料, 分头诗人

AJAX在select的使用如何激活AJAX?

赞成!
0
否决!

node.tpl.php


	   $form['colors'] = array(
            '#type' => 'select',
            '#options' =>array('red','blue','black','white'),
            '#submit' => array('options_color'),
            '#ajax' => array(
                    'event'=>'change',
                    'callback' =>'options_color',
                    'wrapper' => 'myDiv',
            ));
       echo drupal_render($form);

 

模块上:

function options_color($pid)
{
	if ($type == 'ajax') {
	$output = t("This is some content delivered via AJAX");
	$commands = array();
	// See ajax_example_advanced.inc for more details on the available commands
	// and how to use them.
	//$commands[] = ajax_command_append('#myDiv', $output);
	$commands[] = ajax_command_replace('#myDiv', $output);
	$commands[] = ajax_command_replace('#myDiv2', '第二个');
	$page = array('#type' => 'ajax', '#commands' => $commands);
	ajax_deliver($page);
  }
  else {
	$output = t("This is some content delivered via a page load.");
	return $output;
  }
}

 

但下拉框选择的时候没有反应,摸索了2天不知道怎么整,大侠们能否指点一下?