无法读取 jquery 中未定义的 属性 'join'
Cannot read property 'join' of undefined in jquery
我的urllink是这样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");
}
});
但我收到错误
Cannot read property 'join' of undefined
我的 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();
})
});
我认为您的问题是 e.val
未定义。尝试将其替换为 e.target.value
我的urllink是这样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");
}
});
但我收到错误
Cannot read property 'join' of undefined
我的 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();
})
});
我认为您的问题是 e.val
未定义。尝试将其替换为 e.target.value