【问题标题】:codeigniter form_dropdowncodeigniter form_dropdown
【发布时间】:2011-08-17 13:51:43
【问题描述】:

如何使用代码点火器禁用下拉框中的选项?我想禁用该下拉框中的值“------”

       echo "<tr class='background1'><td class='checkoutfield'>";
       $countryall='';
       $select='';
       if(isset($order)) $country=$order['varShippingCountry']; else $country='';
       if(isset($countries) && $countries !='') {
           $countryall['']="Select";
        foreach($countries as $key=>$value):
        $countryall["226/United States"]="United States";
      if($value['id'] !='226') {
//<option value=”spider” disabled=”disabled”>Spider</option>
      $countryall['0']="-------------------------------------------------------";
 $countryall["$value[id]/$value[varPrintableName]"]=$value['varPrintableName'];

       }
        if($value['id'] == $country)
        $select="$value[id]/$value[varPrintableName]";
       endforeach;
         }
          $selFunc='style="width:190px;" id="varShippingCountry" class="required" onchange="stateajax(this.value)"  onKeyup="return changeText(\'varShippingCountry\',\'varPaymentCountry\',\'this.value\')"';
        echo form_label('Country','varShippingCountry')."<span class='mandatory'>*</span></td><td>";

echo form_dropdown('varShippingCountry',$countryall,$selFunc);

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    您不能禁用 HTML 选择元素中的项目 - 只能禁用整个元素。

    您是否尝试在列表的不同部分之间进行分隔?在这种情况下,您可以使用&lt;optgroup&gt;

    <select>
      <optgroup label="Swedish Cars">
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
      </optgroup>
      <optgroup label="German Cars">
        <option value="mercedes">Mercedes</option>
        <option value="audi">Audi</option>
      </optgroup>
    </select>
    

    您可以在 CodeIgniter 中通过传递一个多维数组来实现这一点。

    或者,如果您只是想让第一个和默认项看起来像 ------,然后以正常方式添加它并使用空值。然后在验证时,检查是否没有传递空值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      相关资源
      最近更新 更多