我的网址链接就像这样http://localhost:50255/product/filter/manufacturer/3

在文档加载时,我尝试像这样设置manufacturer 3

$(window).load(function(){
    var pathname = window.location.pathname.split("/");
    var filter = pathname[pathname.length-3];
            if(filter === 'filter'){
                var option = pathname[pathname.length-2];
                var id = pathname[pathname.length-1];
                $("#ManufacturerID").val(id).trigger("change");
            }
        });


但是我得到了错误


  无法读取未定义的属性“ join”


我的html标记是

  <div class="select2-container select2-container-multi js-example-basic-multiple col-sm-12" id="s2id_ManufacturerID" style="border: 1px solid rgba(0, 0, 0, 0.14902); display: block;">
         <ul class="select2-choices">
           <li class="select2-search-field">
           <label for="s2id_autogen6" class="select2-offscreen"></label>
           <input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input select2-default" id="s2id_autogen6" placeholder="" style="width: 1004px;">
           </li>
         </ul>
       <div class="select2-drop select2-drop-multi select2-display-none select2-drop-active">
         <ul class="select2-results">
           <li class="select2-no-results">No matches found</li>
         </ul>
       </div>
    </div>


    <select id="ManufacturerID" class="js-example-basic-multiple col-sm-12" multiple="multiple" placeholder="Κατασκευαστές" style="border: 1px solid rgba(0, 0, 0, 0.14902); display: none;" tabindex="-1">
         <option value="1">manufacturer 1</option>
         <option value="2">manufacturer 2</option>
         <option value="3">manufacturer 3</option>
    </select>


我在这里做错了什么?

由于注释的更新,错误来自以下功能

$(function () {
            $('select').select2()
            .on("change", function (e) {
                var id = '#sel' + $(this).attr("id");
                var array = e.val.join(",");
                $(id).val(array);
                PostIt();
            })
        });

最佳答案

我相信您的问题是e.val是不确定的。尝试将其替换为e.target.value

关于javascript - 无法读取jQuery中未定义的属性“join”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36482323/

10-11 05:55