我的网址链接就像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");
}
});
但我收到了错误
无法阅读财产'加入'未定义的
我的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>
我在这里做错了什么?
UPDATE 感谢评论,错误来自以下函数
$(function () {
$('select').select2()
.on("change", function (e) {
var id = '#sel' + $(this).attr("id");
var array = e.val.join(",");
$(id).val(array);
PostIt();
})
});
答案 0 :(得分:1)
我相信你的问题是e.val
未定义。尝试将其替换为e.target.value