Zend_Form_Element_Select setValue 正在选择多个选项
我正在使用 Zend 1.11.10,并且尝试在下拉列表中设置一个值。我的代码是:
$state = new Zend_Form_Element_Select("mytest");
$state->setLabel("mytest")
->setName("mytest");
$state->addMultiOption('Pear','PE');
$state->addMultiOption('Banana','BA');
$state->addMultiOption('Orange','OR');
$state->addMultiOption('Kiwi','KI');
$state->setValue('Banana');
$this->addElement($state);
问题是生成的 HTML 代码是:
<select id="mytest" name="mytest" style="opacity: 0;"><option value="PE">Pear</option><option selected="selected" value="BA">Banana</option><option selected="selected" value="OR">Orange</option><option selected="selected" value="KI">Kiwi</option></select>
它正在“选择”“Banana”之后的所有选项。这是 Zend 中的错误吗?
I am using Zend 1.11.10 and I am trying to set a value in a dropdown list. My code is:
$state = new Zend_Form_Element_Select("mytest");
$state->setLabel("mytest")
->setName("mytest");
$state->addMultiOption('Pear','PE');
$state->addMultiOption('Banana','BA');
$state->addMultiOption('Orange','OR');
$state->addMultiOption('Kiwi','KI');
$state->setValue('Banana');
$this->addElement($state);
The problem is that the generated HTML code is:
<select id="mytest" name="mytest" style="opacity: 0;"><option value="PE">Pear</option><option selected="selected" value="BA">Banana</option><option selected="selected" value="OR">Orange</option><option selected="selected" value="KI">Kiwi</option></select>
It is making "selected" all options after "Banana". Is this a bug in Zend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,您正在使用非标准
FormSelect
视图助手。对于初学者来说,您的value
属性和文本值是相反的,并且您没有label
属性。例如,对于
生成的标记应该是,
我还大胆猜测,由于不透明度样式属性,有一些 JavaScript 在处理 DOM。
Looks to me like you're using a non-standard
FormSelect
view helper. For starters, your<option>
value
attribute and text values are reversed and you have nolabel
attributes.Eg, for
the generated markup should be
I'd also hazard a guess that there's some JavaScript playing with the DOM due to the opacity style attribute.
完全使用你的代码我得到:
这也是 1.11.10 的。您是否使用自定义表单类或其他可能影响它的内容?
Using your code exactly I get:
this is also with 1.11.10. Are you using custom form classes or anything else that might be affecting it?