【发布时间】:2013-06-13 10:59:45
【问题描述】:
我需要在 Joomla 2.5 的 JHtml 通用列表中为单个选项添加数据属性。
在标准 html 中,选择列表如下所示:
<select class="field" placeholder="<?php echo JText::_('COUNTRY')?>" name="country" id="country" autofocus="autofocus" autocorrect="off" autocomplete="off">
<option value="" selected="selected">Select Country</option>
<option value="Afghanistan" data-alternative-spellings="AF">Afghanistan</option>
<option value="Åland Islands" data-alternative-spellings="AX Aaland Aland" data-relevancy-booster="0.5">Åland Islands</option>
<option value="Albania" data-alternative-spellings="AL">Albania</option>
...
</select>
通常在创建选项时我会这样做:
$options=array();
$options[]=JHTML::_( 'select.option', "Afghanistan", "Afghanistan" );
$options[]=JHTML::_( 'select.option', "Albania", "Albania" );
...
$dropdown = JHTML::_('select.genericlist',$options,'country','id="country" autofocus="autofocus" autocorrect="off" autocomplete="off"','value','text',$default);
如何将 data-alternative-spellings="AF" 添加到每个选项?
谢谢
【问题讨论】:
-
不想这么说,但是 JHtmlSelect::option() 没有任何规定可以添加这个。
-
很酷的功能创意,但我认为现在你需要扩展它。
-
同意上述观点,您可能不得不自己动手。 JHTML 的注册功能允许您添加自己的选项。
-
好的,看来我得扩展它了。谢谢大家!