[英]object is null when setting checked state
So i have a page that has a couple of jQuery plugins. 所以我有一个页面,其中包含几个jQuery插件。 Among other things i have the multiselect toolbar, a pretty sweet plugin. 除其他外,我还有多重选择工具栏,一个漂亮的插件。 problem is that when i load up the page in internet explorer the page breaks. 问题是,当我在Internet Explorer中加载页面时,页面中断。 i've been able to determine that the problem occurs when i try to set some attributes to some elements that i have dynamically generated. 当我尝试将某些属性设置为动态生成的某些元素时,我已经能够确定问题是否出现。
here is the code for generating the elements: 这是生成元素的代码:
$.ajax({
url: '@Url.Content("~")' + 'Ticket/GetTvrtke',
async: false,
success: function (data) {
document.getElementById("header_tvrtka_holder").innerHTML = data;
var tvrtke = data.split(", ");
for (var i = 0; i < tvrtke.length; i++) {
document.getElementById("KlijentMultiSelect").innerHTML +=
"<option value=\"" + tvrtke[i] + "\" id=\"" + tvrtke[i] + "\" >" + tvrtke[i] + "</option>";
}
$("#KlijentMultiSelect").multiselect({
selectedText: "",
height: 125,
minWidth: 650,
noneSelectedText: 'Izaberite željene tvrtke:'
});
}
});
the function gets the correct data and generates the options, and then i activate the plugin to render the new dropdown menu with checkboxes. 该函数获取正确的数据并生成选项,然后我激活该插件以使用复选框呈现新的下拉菜单。
problem is that afterwards i have this code: 问题是之后我有此代码:
var tvrtke = document.getElementById("header_tvrtka_holder").innerHTML.split(", ");
for (var i = 0; i < tvrtke.length; i++) {
document.getElementById("ui-multiselect-" + tvrtke[i]).checked = true;
}
for (var i = 0; i < tvrtke.length; i++) {
document.getElementById("ui-multiselect-" + tvrtke[i]).setAttribute("onclick", "ChangeTextKlijent()");
}
here i am trying to set the checkbox values to true and add an on click event to the input element, but then visual studio sends me the error message from the title. 在这里,我试图将复选框的值设置为true,并向输入元素添加一个click事件,但随后Visual Studio从标题向我发送错误消息。 in firefox, everything works great but IE is a whole different story. 在Firefox中,一切正常,但IE则完全不同。
anyone know how to fix this? 有人知道怎么修这个东西吗?
I switched so that my code looks like this: 我进行了切换,使我的代码如下所示:
var tvrtke = document.getElementById("header_tvrtka_holder").innerHTML.split(", ");
$.each(tvrtke, function (index, value) {
$("#KlijentMultiSelect").append("<option value=\"" + value + "\" id=\"" + value + "\" >" + value + "</option>");
});
and now it works. 现在可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.