我试图从现有的下拉菜单字段中禁用输入和选择。我想让它从菜单中加载已经选择的选项,而不给用户提供以任何方式更改它们的机会。那是我的代码:
HTML:
<select data-chosen-width="100%" multiple="multiple" data-chosen-disable-search="" data-placeholder="Choose categories" name="project_category" id="project_category" class="chosen multi-tax-item tax-item required cat_profile" style="display: none;">
<option class=" administrativno cat-115 level-0" value="115">Административно право</option>
<option class=" veshtno cat-120 level-0" value="120">Вещно право</option>
<option class=" danachno cat-127 level-0" value="127" selected="selected">Данъчно право</option>
<option class=" mpp cat-125 level-0" value="125">Международно публично право</option>
<option class=" mchp cat-126 level-0" value="126">Международно частно право</option>
<option class=" nakazatelno cat-117 level-0" value="117">Наказателно право</option>
<option class=" obligatsionno cat-121 level-0" value="121" selected="selected">Облигационно право</option>
<option class=" osiguritelno cat-124 level-0" value="124" selected="selected">Осигурително право</option>
<option class=" pravo-na-es cat-128 level-0" value="128">Право на Европейския съюз</option>
<option class=" pris cat-123 level-0" value="123">Право на интелектуалната собственост</option>
<option class=" semeino-nasledstveno cat-119 level-0" value="119">Семейно и наследствено право</option>
<option class=" trudovo cat-116 level-0" value="116">Трудово право</option>
<option class=" targovsko cat-122 level-0" value="122">Търговско право</option>
<option class=" finansovo cat-118 level-0" value="118">Финансово право</option>
</select>
<div class="chosen-container chosen-container-multi" style="width: 350px;" title="" id="project_category_chosen">
<ul class="chosen-choices">
<li class="search-choice">
<span>Данъчно право</span>
<a class="search-choice-close" data-option-array-index="2"></a>
</li>
<li class="search-choice">
<span>Облигационно право</span>
<a class="search-choice-close" data-option-array-index="6"></a>
</li>
<li class="search-choice">
<span>Осигурително право</span>
<a class="search-choice-close" data-option-array-index="7"></a>
</li>
<li class="search-field">
<input value="Choose categories" class="valid" autocomplete="off" style="width: 25px;" type="text">
</li>
</ul>
<div class="chosen-drop">
<ul class="chosen-results"></ul>
</div>
</div>
PHP:
$cate_arr = array();
if(!empty($profile->tax_input['project_category'])){
foreach ($profile->tax_input['project_category'] as $key => $value) {
$cate_arr[] = $value->term_id;
};
}
ae_tax_dropdown(
'project_category',
array(
'attr' => 'data-chosen-width="100%" multiple="multiple" data-chosen-disable-search="" data-placeholder="'.__("Choose categories", ET_DOMAIN).'"',
'class' => 'chosen multi-tax-item tax-item required cat_profile',
'hide_empty' => false,
'hierarchical' => true ,
'id' => 'project_category' ,
'selected' => $cate_arr,
'show_option_all' => false
)
);
我尝试添加一些我在网上找到的代码示例,但到目前为止还没有任何实际工作。如果您提出一些想法或解决方案,将会很高兴。感谢。
答案 0 :(得分:0)
尝试添加属性禁用=&#34;禁用&#34;选择。 e.g
<select disabled="disabled"></select>
如果您使用PHP编写。请尝试将这些代码输出到页面:
<script>
$('select').attr('disabled', 'disabled');
</script>
答案 1 :(得分:0)
我通过添加disabled =&#34; true&#34;解决了这个问题。到了&#39; attr&#39; ae_tax_dropdown&#39;,所以它现在看起来像这样:
'attr' => 'data-chosen-width="100%" multiple="multiple" data-chosen-disable-search="" data-placeholder="'.__("Choose categories", ET_DOMAIN).'" disabled="true"'