douduan1953 2012-04-07 04:49
浏览 1131
已采纳

为select元素设置占位符

I have a ZendX_Jquery_Form where I am having a trouble setting placeHolder for a select Element.

$month->setAttribs(
        array(
            'required'  =>  TRUE,
            'placeHolder'   =>  'Month'
        ));

I wanted it too look like this: enter image description here

but all I am getting is thi: enter image description here

On my firebug output html looks like this

<select id="months_at_residence-lengthMonth" placeholder="Month" required="1" name="months_at_residence[lengthMonth]">

I have absolutely no idea why this is not working.

I need help to set this such that when i click on it placeholder text hides. Just incase this dont work straight using zend I know this can be done using js/css . If I do it with css and javascript how can I achieve this for all select elements ?

Hope the question was clear enough

  • 写回答

3条回答 默认 最新

  • douzhi4311 2012-04-07 05:54
    关注

    Placeholders don't work with select form element, what you should do instead is to use a default value and disable it as follows:

    $month->addMultiOption('--', 'Month');
    $month->setOptions(array('disable' => array('--')));
    

    This will output:

    <select id="country" name="country" class="valid">
        <option disabled="disabled" label="--" value="--">Month</option>
        <option label="January" value="Jan">January</option>
        <option label="February" value="Feb">February</option>
        // ...
    </select>
    

    Note from W3Schools:

    The placeholder attribute works with the following input types: text, search, url, tel, email, and password.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条