隐藏下拉框中的option[兼容firefoxIE]

//****** Hide and Show Option Function *******/
//hide option
function hideone(theselect,index)
{
    var oldOption = theselect.children[index];
    var oldStr   = oldOption.innerText;
    var newOption = document.createElement('div');
    newOption.setAttribute('opndatasourceid',oldOption.getAttribute('opndatasourceid'));
    newOption.setAttribute('opngoalstmtgroupids',oldOption.getAttribute('opngoalstmtgroupids'));
    newOption.setAttribute('opngoalstmtdesc',oldOption.getAttribute('opngoalstmtdesc'));
    newOption.setAttribute('opngoalstmtvalue',oldOption.getAttribute('opngoalstmtvalue'));
    newOption.setAttribute('value',oldOption.getAttribute('value'));
    newOption.setAttribute('orderindex',oldOption.getAttribute('orderindex'));
    newOption.innerText   = oldStr;
    theselect.appendChild(newOption);
    theselect.replaceChild(newOption,oldOption);
    newOption.style.display = 'none';
   
    document.getElementById("goalstmtdesc").value = "";//clear description textarea
}
//show option
function showone(theselect,index)
{
    var oldOption = theselect.children[index];
    if(oldOption.tagName=='DIV')
    {
        var oldStr   = oldOption.innerText;
        var newOption = document.createElement('option');
        newOption.setAttribute('opndatasourceid',oldOption.getAttribute('opndatasourceid'));
        newOption.setAttribute('opngoalstmtgroupids',oldOption.getAttribute('opngoalstmtgroupids'));
        newOption.setAttribute('opngoalstmtdesc',oldOption.getAttribute('opngoalstmtdesc'));
        newOption.setAttribute('opngoalstmtvalue',oldOption.getAttribute('opngoalstmtvalue'));
        newOption.setAttribute('value',oldOption.getAttribute('value'));
        newOption.setAttribute('orderindex',oldOption.getAttribute('orderindex'));
        newOption.innerText   = oldStr;
        theselect.appendChild(newOption);
        theselect.replaceChild(newOption,oldOption);
    }
}

有时间,好好整理一下!

posted @ 2009-06-08 16:49  北北  阅读(826)  评论(0编辑  收藏  举报