javascript - 使用 dispatchEvent 预填充表单字段在 IE 中不起作用,在其余所有浏览器中工作正常

标签 javascript jquery reactjs

我的应用程序是使用 React 创建的。通过使用 dispatchEvent 我试图使用 JS 预填充表单字段值。它在所有浏览器中都能正常工作,但在 IE 11 中不行。

IE 控制台显示对象不支持错误。

我用来预填表单字段的代码。

$(document.body).on('change', '#retailer', function() {

        var retail_val = $(this).val();

        //Storing the retailer value in the respective hidden text field.
        if (retail_val != "0") {
            var el = document.getElementById("text_6551650686371-InputField");
            el.value = retail_val;
        //calling the function
            doEvent(el, 'input');

        }
        if (retail_val == "0") {
            var el = document.getElementById("text_6551650686371-InputField");
            el.value = "";
          //calling the function
            doEvent(el, 'input');

        }
});
function doEvent(obj, event) {
         event = new Event(event, {
            target: obj,
            bubbles: true
        });

        return obj ? obj.dispatchEvent(event) : false;
    }

This is the error screenshot in IE 11 注意:我尝试使用 .val() 方法,因为我的应用程序是使用 React 创建的,它无法正常工作。请帮我在 IE 中预填表单字段值。此外,当我更改选项卡时,字段中的值会关闭。

最佳答案

根据 this answer ,如果您将事件名称更改为“textinput”(检查浏览器后执行此操作),它可能会起作用

关于javascript - 使用 dispatchEvent 预填充表单字段在 IE 中不起作用,在其余所有浏览器中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45428515/

相关文章:

javascript - jQuery:如何动态地将表属性添加到一行中的特定单元格?

javascript - reactjs 中的反模式到底是什么?

javascript - react js : How to open a local path via HTML button on webpage

javascript - FlotChart - 如何为折线图中的特定系列分配颜色?

javascript - Safari Extjs 网格渲染问题

jquery - 当 child 获得新类(class)时向父级添加类(class)?

javascript - 将计算总和插入输入

reactjs - 在屏幕上显示图像之前触发事件?

javascript - Jquery网格仅在第一次单击时加载,并且在后续单击时不重新加载

javascript - 添加键码事件处理程序后如何将其删除?