【问题标题】:Laravel - Disable option value after selecting it onceLaravel - 选择一次后禁用选项值
【发布时间】:2018-01-30 14:46:24
【问题描述】:

我的项目中有一个表单,用户正在使用它来填写应用程序。 在这种形式中,我有一个表格,其中包含有关用户语言技能的详细信息。 此外,在我的项目中,我有一个播种器,其中包含表中选项选择中显示的所有语言。

其中一种语言被选中一次后如何禁用它?

这是我的一些代码示例:

HTML:

<td id="resource_profile_languages">
  <select {{ (FALSE == $canEdit) ? 'readonly':'' }} class="form-control form-select" id="{{ 'resource_profile_language_'.$index }}" name="{{ 'resource_profile_language_'.$index }}" placeholder="Language">
    @foreach($languages as $r=>$language)
      <option {{ ($language->name == $resourceProfileLanguage->language->name) ? 'selected':'' }} value="{{ $language->value }}" >{{ $language->name }}</option>
    @endforeach
  </select>
</td>

这是我在表格中添加新语言的脚本方式:

function addNewLanguage(){
    var count = $('#resource_profile_language_table').children('tr').length;

    var select_language = $('#resource_profile_languages')
                            .children([CONST_ENGLISH_ID])
                            .clone()
                            .attr('id', idResourceProfileLanguage.concat(count))
                            .attr('name', idResourceProfileLanguage.concat(count));


    $('#resource_profile_language_table').append($('<tr>').append( $('<td id="resource_profile_languages_' + count + '" name="resource_profile_languges_' + count + '">').append(select_language)));
  }

【问题讨论】:

    标签: javascript php jquery html laravel-5


    【解决方案1】:

    您需要在 select 中监听 change 事件。由于选择的 ID 是动态的,因此您可以使用 Blade 语法,只要它内联/包含在模板中即可。比如:

    $("#{{ 'resource_profile_language_'.$index }}").on("change", function(){
         $("#{{ 'resource_profile_language_'.$index }} option:selected").attr("disabled","disabled")
        .siblings();
     });
    

    【讨论】:

      猜你喜欢
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      • 2022-01-15
      • 1970-01-01
      • 2023-03-30
      相关资源
      最近更新 更多