使用 Drupal 7 表单 API,如何在提交 AJAX 表单之前提示 javascript 确认框?我尝试了不同的可能方法来做到这一点,但没有成功。这是代码:
function create_list_form($form, &$form_state) {
$form['list_name'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'List Name'
'#attributes' => array()
);
$form['list_desc'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'List Desc'
'#attributes' => array()
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#attributes' => array('class' => array('use-ajax-submit')),
'#value' => 'Create List'
);
return $form;
}
这是Javascript代码:
Drupal.behaviors.module = {
attach: function() {
jQuery('#edit-submit').click(function(){
if(!confirm('Are you sure?'))
return false;
});
}
}