JavaScript.click 在 IE 11 中不起作用

JavaScript .click doesnt work in IE 11

我一直在尝试让此代码适用于动态 crm 的多个 select 选项集。我的问题是这段代码在 Chrome 中毫不费力地工作,完全符合我的要求,但在 IE 中,.click 事件 returns false 无论如何,如果复选框被选中或未选中。

所有这些代码所做的就是获取一个选项集并将其转换为多 select 列表并将值设置到两个字段中 "l1s_trainingmodulesvalues" 保存选项的值 selected "l1s_trainingmodules" 保存选项的标签 selected.

有人可以看看我做错了什么吗?

<html><head>
<title></title>
<script src="../WebResources/new_jquery3.1.1.min.js" type="text/javascript"></script>
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script type="text/javascript">

        // function will be called when web resource is loaded on Form.
        $(document).ready(function () 
        {
            ConvertDropDownToCheckBoxList();
        });

        //Coverts option list to checkbox list.
function ConvertDropDownToCheckBoxList() 
{
    var dropdownOptions = parent.Xrm.Page.getAttribute("l1s_trainingmodulesoptionset").getOptions();
    var selectedValue = parent.Xrm.Page.getAttribute("l1s_trainingmodulesvalues").getValue();

    $(dropdownOptions).each(function (i, e) 
    {
        var rText = $(this)[0].text;
        var rvalue = $(this)[0].value;
        var isChecked = false;
        if (rText != '') 
        {
            if (selectedValue != null && selectedValue.indexOf(rvalue) != -1)
                isChecked = true;

            var checkbox = "<label><input type=\"checkbox\"  name =\"r\">" + rText  + "<br></label>"
            $(checkbox)
                .attr("value", rvalue)
                .attr("checked", isChecked)
                .attr("id", "id" + rvalue)
                .on('click',function () 
                {
                    //To Set Picklist Select Values
                    var selectedOption = parent.Xrm.Page.getAttribute("l1s_trainingmodulesvalues").getValue();
                    alert($(this).is(':checked')); /*** This value always returns false in IE but in Chrome it works perfectly*/**
                    if ($(this).is(':checked')) 
                    {
                        if (selectedOption == null)
                            selectedOption = rvalue+"";
                        else
                            selectedOption = selectedOption + "," + rvalue
                    }
                    else 
                    {
                        var tempSelected = rvalue + ",";
                        if (selectedOption != null) 
                        {
                            if (selectedOption.indexOf(tempSelected) != -1)
                                selectedOption = selectedOption.replace(tempSelected, "");
                            else
                                selectedOption = selectedOption.replace(rvalue, "")
                        }
                    }
                    //alert(rvalue);
                    parent.Xrm.Page.getAttribute("l1s_trainingmodulesvalues").setValue(selectedOption);

                    //To Set Picklist Select Text
                    var selectedYear = parent.Xrm.Page.getAttribute("l1s_trainingmodules").getValue();
                    if ($(this).is(':checked')) 
                    {
                        if (selectedYear == null)
                            selectedYear = rText+"";
                        else
                            selectedYear = selectedYear + "," + rText
                    }
                    else 
                    {
                        var tempSelectedtext = rText + ",";
                        if (selectedYear != null) 
                        {
                            if (selectedYear.indexOf(tempSelectedtext) != -1)
                                selectedYear = selectedYear.replace(tempSelectedtext, "");
                            else
                                selectedYear = selectedYear.replace(rText, "");
                        }
                    }
                    //alert(selectedYear);
                    parent.Xrm.Page.getAttribute("l1s_trainingmodules").setValue(selectedYear);

                })
                .appendTo(checkboxList);
        }
    });
}
</script>  
<meta charset="utf-8">
</head><body style="-ms-word-wrap: break-word;"><form><div id="checkboxList">
</div></form>
</body></html>

您的 checkbox 变量没有引用复选框元素。这是一个标签 (var checkbox = "<label><input type=\"checkbox\" name =\"r\">" + rText + "<br></label>"),没有选中状态。

在您的 click 处理程序中,更改

if ($(this).is(':checked'))

if ($(this).find('input').is(':checked'))