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条)

报告相同问题?

悬赏问题

  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法