禁用在IE中工作但在Firefox中不起作用

时间:2012-05-26 09:39:09

标签: javascript asp.net cross-browser

这是我的javascript代码。在加载功能我必须禁用btndelete ..在iE中正常工作,但在Firefox中,但是不是dsabled ..我不知道这是一个CSS问题还是什么?

的Javascript

 window.onload = body_Onload;

            function body_Onload()
            {
                    var btnDelete = document.getElementById('<%=btnDelete.ClientID%>');
                btnDelete.disabled = true;
            }

HTML

<asp:Button ID="btnDelete" runat="server" CssClass="cssbutton" Text="Delete" Width="60px" OnClick="btnDelete_Click" />

CSS

.cssbutton
{
    font-weight: bold;  
    border-right: #3C8FD1 1px solid;
    border-top: #3C8FD1 1px solid;
    border-left: #3C8FD1 1px solid;
    border-bottom: #3C8FD1 1px solid;
    font-size: 10px;
    color: #045FA7;
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    background-image: url(../App_Images/cssbuttonbg.gif);
    line-height: 14px;
}

HTML生成的代码

<input type="submit" name="pageMain$contentPlaceHolderMain$btnDelete" 
    value="Delete" onclick="return btnDelete_Click();"
    id="contentPlaceHolderMain_btnDelete" class="cssbutton" style="width:60px;"/>

1 个答案:

答案 0 :(得分:4)

以下是我根据您的问题和评论中的信息制作的示例页面:

这适用于IE和FireFox。不同的是,在IE中,按钮在禁用时显示为灰色。在FireFox中,按钮看起来相同,但已禁用。因此,您可能希望为其分配一个类以及为FireFox设置灰色的样式。

<!DOCTYPE html>
<html>
<head>

<script>
function body_Onload()
{
    var btnDelete = document.getElementById('contentPlaceHolderMain_btnDelete');
        btnDelete.disabled = true;
        btnDelete.className += ' btndisabled';
}
</script>
<style>
.cssbutton
{
    font-weight: bold;  
    border-right: #3C8FD1 1px solid;
    border-top: #3C8FD1 1px solid;
    border-left: #3C8FD1 1px solid;
    border-bottom: #3C8FD1 1px solid;
    font-size: 10px;
    color: #045FA7;
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    background-image: url(../App_Images/cssbuttonbg.gif);
    line-height: 14px;
}
.btndisabled 
{
    background-color: rgb(236,233,216);
    color: #CCC;
    font-style:normal;
}
</style>
</head>
<body onload="body_Onload();">
<form>
<input type="submit" name="pageMain$contentPlaceHolderMain$btnDelete" 
    value="Delete" onclick="return btnDelete_Click();"
    id="contentPlaceHolderMain_btnDelete" class="cssbutton" style="width:60px;"/>
</form>
</body>
</html>