dslijian2015
2017-10-25 09:55
浏览 47
已采纳

根据条件,如何使下拉列表单选或多选?

I had a requirement where in an employee list dropdown given, if selectMultiple is set, the dropdown should allow multiple selects, and if selectMultiple is not set, it shouldn't.

<select name="employeeList[]" id="employeeList" class="form-
control" multiple="<?=$selectMultiple?>">
    <?php
    foreach($employeeList as $employee) {

        echo "<option value='" . $employee->$employeeId . "'>" . 
        $employee->employeeName . "</option>";

    }    
    ?>
</select>

It's a phtml file, and $selectMultiple is passed from a controller(as in Phalcon). I have tried something like passing, $selectMultiple ="multiple", so the code will look like

<select name="employeeList[]" id="employeeList" class="form-control" multiple="multiple">

and $selectMultiple="" for the single select case.

<select name="employeeList[]" id="employeeList" class="form-control" multiple="">

But the very presence of multiple attribute itself makes the dropdown list elligible for multiselect.

In short, in either cases, it triggers multiselect regardless of the condition. Please help.

图片转代码服务由CSDN问答提供 功能建议

我有一个要求,在给定的员工列表下拉列表中, 如果设置了selectMultiple,则下拉列表应允许多个选择 ,如果未设置selectMultiple,则不应该。</ p>

 &lt; select name =“employeeList []”id =“employeeList”class =“form- 
control”  multiple =“&lt;?= $ selectMultiple?&gt;”&gt; 
&lt;?php 
 foreach($ employeeList as $ employee){
 
 echo“&lt; option value ='”。  $ employee-&gt; $ employeeId。  “'&gt;” 中 。  
 $ employee-&gt; employeeName。  “&lt; / option&gt;”; 
 
} 
?&gt; 
&lt; / select&gt; 
 </ code> </ pre> 
 
 

这是 phtml </ code >文件, $ selectMultiple </ code>从控制器传递(如在Phalcon中)。 我尝试了传递, $ selectMultiple =“multiple”</ code>之类的东西,所以代码看起来像</ p>

 &lt; select name =“employeeList []  “id =”employeeList“class =”form-control“multiple =”multiple“&gt; 
 </ code> </ pre> 
 
 

$ selectMultiple =”“</ code> 对于单个选择案例。</ p>

 &lt; select name =“employeeList []”id =“employeeList”class =“form-control”multiple =“”&gt; 
  </ code> </ pre> 
 
 

但是多个属性本身的存在使得下拉列表对于多重选择来说是合格的。</ p>

简而言之,在任何一种情况下,它都是 无论条件如何,都会触发多重选择。 请帮忙。 </ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题