drwu24647 2015-10-31 16:19
浏览 71
已采纳

laravel PHP空格字符中的下拉列表不起作用

i have two dropdowns, and when I click on item inside the first one, the second one is automaticaly updated, i am doing this with JQuery. It's working fine, but only if there is not space characters inside the Item from the first list, so for example if I have "Some item" as item, it will do nothing, but for "item" it will update another list. Here is the Jquery code, and Laravel PHP code. Can you please tell me why it's making problem with spaces inside first dropdown?

  <select name="podrucje" id="select1" style='width: 150px;'>                     
          @foreach( $projects_all as $project )
           <? if ($project->name != null)  { ?>

      <option value="{{ $project->podrucje }}">{{ $project->name}}</option>

               <? }  ?>
      @endforeach
      </select>

This is Jquery Script for on item change for the first list:

     $("#select1").change(function () {
    if ($(this).data('options') == undefined) {
        /*Taking an array of all options-2 and kind of embedding it on the select1*/
        $(this).data('options', $('#select2 option').clone());
    }
    var id = $(this).val();
    var options = $(this).data('options').filter('[value=' + id + ']');
    $('#select2').html(options);



    });
  • 写回答

2条回答 默认 最新

  • dongpo5264 2015-10-31 16:49
    关注

    seems to work if you put double quotes around the value in your filter.

    so line 7 of your js would become

    var options = $(this).data('options').filter('[value="' + id + '"]');
    

    see this for working example (last value in dropdown had space in value)

    https://jsfiddle.net/5mb7oot4/1/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化