在ie7中第二次选择时挂起的javascript选择框

时间:2010-04-27 20:28:22

标签: javascript javascript-events internet-explorer-7

我在div中有一个下拉选择框。当用户单击更改时,更改/提交按钮旁边会出现一个下拉框,用户会进行选择,然后更新数据库并显示选择而不是下拉列表。所有在IE8和Firefox中工作正常,但在IE7中它允许一个选择(有几个相同的下拉菜单),但第二次选择,它挂起,请等待。这是相关代码

<td width=200>

<input type="button" onclick="startChanging(this)" value="Change" /></td>

<script type="text/javascript">
var selectBox, isEditing = false;
var recordvalue;
if( window.XMLHttpRequest ) {
    recordvalue = new XMLHttpRequest();
} else if( window.ActiveXObject ) {
    try {
        recordvalue = new ActiveXObject('Microsoft.XMLHTTP');
    } catch(e) {}
}
window.onload = function () {
    selectBox = document.getElementById('changer');
    selectBox.id = '';
    selectBox.parentNode.removeChild(selectBox);

};
function startChanging(whatButton) {
    if( isEditing && isEditing != whatButton ) { return; } //no editing of other entries
    if( isEditing == whatButton ) { changeSelect(whatButton); return; } //this time, act as "submit"
    isEditing = whatButton;
    whatButton.value = 'Submit';
    var theRow = whatButton.parentNode.parentNode;
    var stateCell = theRow.cells[3]; //the cell that says "present"
    stateCell.className = 'editing'; //so you can use CSS to remove the background colour
    stateCell.replaceChild(selectBox,stateCell.firstChild); //PRESENT is replaced with the select input
    selectBox.selectedIndex = 0;
}
function changeSelect(whatButton) {
    isEditing = true; //don't allow it to be clicked until submission is complete
    whatButton.value = 'Change';
    var stateCell = selectBox.parentNode;
    var theRow = stateCell.parentNode;
    var editid = theRow.cells[0].firstChild.firstChild.nodeValue; //text inside the first cell
    var value = selectBox.firstChild.options[selectBox.firstChild.selectedIndex].value; //the option they chose

    selectBox.parentNode.replaceChild(document.createTextNode('Please wait...'),selectBox);
    if( !recordvalue ) {
        //allow fallback to basic HTTP
        location.href = 'getupdate.php?id='+editid+'&newvalue='+value;
    } else {
        recordvalue.onreadystatechange = function () {
            if( recordvalue.readyState != 4 ) { return; }
            if( recordvalue.status >= 300 ) { alert('An error occurred when trying to update'); }
            isEditing = false;
            newState = recordvalue.responseText.split("|");
            stateCell.className = newState[0];
            stateCell.firstChild.nodeValue = newState[1] || 'Server response was not correct';
        };
        recordvalue.open('GET', "getupdate.php?id="+editid+"&newvalue="+value, true);
        recordvalue.send(null);
    }
}
</script>    

如果有人知道为什么会这样,我会非常感激

1 个答案:

答案 0 :(得分:1)

确定设法解决它。我将recordvalue.open行移到了最后一个其他循环的底部附近,它在所有浏览器中完美运行只是不要问我为什么