0

Forms API 中的表单控件是否有 id?下面是我的示例代码:

function myid_user_page_form(){  
    $form = array();
    $form['id'] = array(
        '#type' => 'fieldset',
        '#title' => t('ID Information'),
        '#collapsible' => TRUE, 
        '#collapsed' => FALSE,
    );  
    $form['id']['myphoto_button'] = array(
        '#type' => 'button', 
        '#value' => '...',
        '#attributes' => array(
        'onclick' => "myphoto_options();",),  
    );
    return $form;
 }

对于这个非常简单的初学者问题很抱歉,但是如何在上面的示例中识别我的按钮 ID(例如)$form['id']['myphoto_button']?

4

1 回答 1

0

#attributes属性用于设置元素的 html 属性。(like, id, class, style, onclick等)

我可以看到您正在使用它来绑定onclick处理程序。所以,它为了给你的按钮一个 id:

$form['id']['myphoto_button'] = array(
    '#type' => 'button', 
    '#value' => '...',
    '#attributes' => array(
        'onclick' => "myphoto_options();",
        'id'      => 'YOUR-BUTTON-ID',
    ),  
);
于 2015-02-04T08:47:07.777 回答