繁体   English   中英

为什么此Dojo 1.9 / JS代码在Internet Explorer 7中不起作用?

[英]Why doesn't this Dojo 1.9/JS code work in Internet Explorer 7?

使用Dojo 1.9的Web应用程序存在问题。 该应用程序可以在Chrome,Firefox和IE 10/11上正常运行,但是我们收到有关IE 7中问题的报告。

不幸的是 ,我无法直接对其进行测试,因为根据公司指令,IE 7已从所有开发人员机器中删除。 因此,我负责修复无法复制的错误。

由于用户的反馈,应用程序中的所有按钮都从type =“ submit”更改为type =“ button”,并且向按钮添加了onclick()处理函数,以便在单击按钮时才提交表单,但是不是在按ENTER键时。 这是dojo / domReady! 连接按钮的代码:

    //  Make the buttons submit the form ONLY on click (avoid keypress)
    query("button[type='button']").on("click", function(e) {
        console.log("    in button onclick handler");
        //  This actually submits the form based on the button that was clicked
        myapp.core.buttonClick("applicationInfo",this);
        console.log("    leaving button onclick handler");
    })

这是实际提交表单(myapp.core.buttonClick)的例程:

    myapp.core.buttonClick = function(formName, buttonObject) {
        // Have to do this to transmit the data - the button info
        // won't be transmitted otherwise
        var formObject = document.forms[formName];
        var newField = document.createElement('input');
        newField.type = 'hidden';
        newField.name = buttonObject.name;
        newField.value = buttonObject.value;
        formObject.appendChild(newField);
        formObject.submit();
    }

熟悉IE7的任何人都可以在此代码中发现问题吗? 提前致谢...

简短答案:IE7和Spring Web Flow不兼容。

长答案:

Dojo 1.9不仅不支持IE 7 ,而且IE7 在Spring Web Flow中也存在很大问题 由于IE7会将所有按钮提交给服务器,而不管单击了什么按钮,因此使用IE7将Web Flow事件传递回服务器很麻烦,并且需要非常丑陋的修改:

var formObject = document.forms[formName];
//  Rip out the buttons because IE7 sucks
for (i=0;i<formObject.length;i++) {
    if (formObject[i].tagName === 'BUTTON') {
        formObject[i].parentNode.removeChild(formObject[i]);
        i--;
    }
}
var newField = document.createElement('input');
newField.type = 'hidden';
newField.id=buttonObject.id;
newField.name = buttonObject.name;
if (buttonObject.attributes['value'] != null) {
    newField.value = buttonObject.attributes['value'].value;
} else {
    newField.value = buttonObject.value;
}
formObject.appendChild(newField);
formObject.submit();

该技巧基本上是从表单中删除所有按钮对象,然后将实际上被单击的一个按钮添加回一个隐藏字段,然后提交表单。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM