Internet Explorer上不显示此DIV

时间:2009-02-18 15:39:41

标签: javascript internet-explorer dom html

我需要做一些警告信息(比如验证等),而我正在用DIV做这件事。

这就是我正在进行验证的方式:

<form action="index.php" method="post" onsubmit="return validateSearchKeyword();">
        <input class="text_search" id="text_search" name="text_search" type="text" value="pesquisar" onfocus="if (this.value=='pesquisar') this.value = ''" onBlur="if (this.value=='') this.value = 'pesquisar'"  />
    </form> 

和验证功能:

function validateSearchKeyword()
{
if (document.getElementById('text_search').value==""){creatediv('divAvisoPesquisa','You must supply a value', '355px', '125px');return false;}
}

这是创建DIV的功能:

function creatediv(id, html, left, top) {

if (document.getElementById(id)) 
    {
        //document.getElementById(id).style.display='block';
        //fadeIn(id, 300);
    }
    else
    {
        var newdiv = document.createElement('div');
        newdiv.setAttribute('id', id);
        newdiv.setAttribute("class", "warningDiv"); 
        newdiv.style.position = "absolute";
        newdiv.innerHTML = html;
        newdiv.style.left = left;
        newdiv.style.top = top;
        newdiv.style.display = "none";
        newdiv.onclick=function(e) {
            $(this).fadeOut(300, function() { $(this).remove(); });
        };  
        document.body.appendChild(newdiv);
        $("#"+id).fadeIn(300); 
    }
} 

fadIn fadeOut 函数来自“jquery-1.3.1.min.js”

CSS ......

.warningDiv{
    -moz-border-radius-bottomleft:15px;
    -moz-border-radius-bottomright:15px;
    -moz-border-radius-topleft:15px;
    -moz-border-radius-topright:15px;
    font-size:11px;
    font-weight:bold;
    height:55px;
    padding:15px 25px;
    width:320px;
    z-index:100000;
    display: block;
}

因此,除了Internet Explorer之外,这适用于所有浏览器。即使验证工作(表单未通过验证时也未提交)但DIV未显示。 我该如何解决这个问题?

由于

2 个答案:

答案 0 :(得分:3)

我想我已经明白了。如果您使用以下内容,IE似乎不会以正确的方式应用类:

    newdiv.setAttribute("class", "warningDiv"); 

请尝试使用此代码:

    newdiv.className="warningDiv";

...我刚刚测试过,它显示了IE开发人员工具栏中所有正确的CSS属性,它没有使用前者。

答案 1 :(得分:1)

我几乎肯定JQuery的.fadeIn在IE6上不起作用。

尝试没有淡入淡出效果的功能或将效果调用更改为:

$("#"+id).fadeIn(300,function() { $(this).show(); });