簡體   English   中英

如何在ZF2表單元素上設置自動對焦?

[英]How do you set autofocus on a ZF2 form element?

如何在ZF2表單元素上設置自動對焦屬性?

我想我們可以在工廠數組中使用setter方法或選項。

在構造方法中添加元素時,可以使用

'autofocus'=>'true'

在該元素的屬性內。 在這里,我將顯示“電子郵件”元素的代碼:

$this->add(array(
        'name' => 'email', 
        'type' => 'Zend\Form\Element\Email',
        'options' => array(
            'label' => 'Email:'
            ),
        'attributes' => array(
            'type' => 'email', 
            'required' => true, 
            'placeholder' => 'myaccount@domain.com', 
            'class' => 'form-control',
            'tabindex' =>'1',
            'id'=>'email',
            'autofocus'=>'true'
            )
        ));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM