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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度