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

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?