所以这就是我想要做的:
1. 我创建并呈现以下表单元素:
$form['rb_download_' . $doc_id] = array(
'#type' => 'submit',
'#name' => 'doc_' . $doc_id,
'#prefix' => "<div id='rb_doc_order_{$doc_id}'>",
'#suffix' => '</div>',
'#value' =>variable_get('rb_order_button', "buyOnline"),
'#ahah' => array(
'event' => 'click',
'path' => "rb/case/doc_order_js/$case->nid/$doc_id",
'wrapper' => "rb_doc_order_{$doc_id}",
'effect' => 'fade',),
);
2. action 函数返回并用新元素替换上面的元素:
function rb_case_doc_order_js($case, $doc_id) {
$button['rb_download_' . $doc_id] = array(
'#type' => 'submit',
'#name' => 'doc_' . $doc_id,
'#prefix' => "<div id='rb_doc_order_{$doc_id}'>",
'#suffix' => '</div>',
'#value' => variable_get('rb_order_confirm', "Remove from cart"),
//'#attributes' => array('class' => 'ahah-processed'),
'#ahah' => array(
'event' => 'click',
'path' => "rb/case/doc_unorder_js/$case->nid/$doc_id",
'wrapper' => "rb_doc_order_{$doc_id}",
'effect' => 'fade',),
);
$output .= drupal_render($button);
$output .= "<script type='text/javascript'>\n";
$output .= "cart_block_item_count($count);\n";
$output .= "Drupal.ahah;\n";
$output .= "</script>\n";
print drupal_json($output);
}
3. 结果是旧按钮被上面那个替换了,但是新按钮没有AJAX
启用。
我需要做什么来AHAH
准备新的返回元素?