0

我创建了一个函数,该函数根据使用 window.onchange 事件在 chrome 和 FF 中正常工作的选择下拉列表的组合显示/隐藏不同的消息。谁能告诉我为什么这在 ie 中不起作用,如果他们有解决方案。

由于内部限制,它必须建在表格中。

    ;(function(){
    document.onchange = function(){
        // Initialise variables for drop down options
        var homeMove        = document.getElementById('homeMove'),
            transferOrder   = document.getElementById('transferOrder'),
            orderComplete   = document.getElementById('orderComplete'),
            submitBtn       = document.getElementById('submitBtn');

        // Initialise variables for comments
        var comment1 = document.getElementById('comment1'),
            comment2 = document.getElementById('comment2'),
            comment3 = document.getElementById('comment3');


        if((homeMove.value == 'No') && (transferOrder.value == 'No')){
            comment2.style.display = 'none';
            comment3.style.display = 'none';
            comment1.style.display = 'block';
            submitBtn.disabled = true;
        }   

        // if Home Move - No AND Transfer Order - Yes. Display nothing. Submit button abled
        if((homeMove.value == 'No') && (transferOrder.value == 'Yes')){
            comment1.style.display = 'none';
            comment2.style.display = 'none';
            comment3.style.display = 'none';
            submitBtn.disabled = false;
        }

        // If Home Move - Yes AND Transfer Order - NO. Display comment1. Submit button disables
        if((homeMove.value == 'Yes') && (transferOrder.value == 'No')){
            comment1.style.display = 'block';
            comment2.style.display = 'none';
            comment3.style.display = 'none';
            submitBtn.disabled = true;
        }

        // If Home Move - Yes AND Transfer Order - Yes AND Order Complete - Yes. Display comment2 Subhmit button abled
        if((homeMove.value == 'Yes') && (transferOrder.value == 'Yes') && (orderComplete.value == 'Yes')){
            comment1.style.display = 'none';
            comment2.style.display = 'block';
            comment3.style.display = 'none';
            submitBtn.disabled = false;
        }   

        // If Home Move - Yes AND Transfer Order - Yes and Order Complete - No. Display comment3. Submit button disabled
        if((homeMove.value == 'Yes') && (transferOrder.value == 'Yes') && (orderComplete.value == 'No')){
            comment1.style.display = 'none';
            comment2.style.display = 'none';
            comment3.style.display = 'block';
            submitBtn.disabled = true;
        }
    }
})();

对此的任何帮助都会很棒。谢谢

4

2 回答 2

0

IE 仅在元素失去焦点时触发 onchange 事件

尝试使用 onclick 事件。

于 2012-07-04T12:38:09.493 回答
0

首先,如果不做一个document.change,添加事件来改变下拉菜单会更好。

有时 onpropertychange 是一个更可靠的镜头事件,可以依赖于 ie。但请确保对于该事件,您通过添加以下过滤器来执行后续检查该事件是否用于更改值:

yourselectboxelement.onpropertychange = function() { 
  if (window.event.propertyName == "value") {   
   // Do stuff here     
  } 
}; 
于 2012-07-04T12:40:29.357 回答