简体   繁体   English

设置检查状态时对象为null

[英]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.

相关问题 单击签入反应时,将行数据存储为处于状态的对象数组 - Store row data as array of object in state when click on checked in react 访问 state 中的 object 属性时返回 null? - Returning null when accessing object properties in state? 在评估this.state时,null不是对象。 - null is not an object when evaluating this.state &#39;checked&#39;为空或不是对象-仅IE - 'checked' is null or not an object - only IE setState 仅在使用 object 作为 state 时设置最后一个输入 - setState only setting last input when using object as state Object.create有什么选择(将状态设置为React组件时)? - What alternatives there are for Object.create (when setting state to React component)? 设置状态对象以进行重新获取时,React 查询隐藏错误消息 - React query hide error message when setting state object for refetching 尝试在组件中导入和使用全局状态时,对象 null 不可迭代 - Object null is not iterable when trying to import and use global state in component Redux state 显示 null[Object object] 即使我已经用数据填充了 state - Redux state shows null[Object object] even when I have filled the state with data 如果设置了选中的属性,则将引导程序按钮设置为按下状态 - Setting bootstrap button to pressed state if checked property is set
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM