1

「onmouseover」イベントを使用してリストボックスを表示および非表示にすることに興味があります。私は ASP.NET にかなり慣れていないので、まだ JavaScript を書きたくありません。次のコードを使用しようとしていますが、色の変更部分は機能しますが、リストボックスの可視性は機能しません:

if (!IsPostBack) { Button2.Attributes.Add("onmouseover", "this.style.backgroundColor='Red', ListBox3.style.visibility='visible'"); }

        if (!IsPostBack)
        {
            Button2.Attributes.Add("onmouseout", "this.style.backgroundColor='Blue', ListBox3.style.visibility='hidden'");
        }

「PostBack」の有無にかかわらずこのコードを試しましたが、まだ運がありません。私のコードが失敗している場所を誰かが見ていますか?

ありがとうございました、

DFM

4

1 に答える 1

2

試す:

    if (!IsPostBack)
    {
        btnHide.Attributes.Add("onmouseout", "this.style.backgroundColor='Blue';ListBox3.style.display='none'");
        btnShow.Attributes.Add("onmouseover", "this.style.backgroundColor='Red';ListBox3.style.display='block'");
    }

可視性プロパティは、表示プロパティとは少し異なる働きをします。表示プロパティを「非表示」に設定すると要素は非表示になりますが、レイアウトは影響を受けませんが、表示プロパティを「なし」に設定すると要素が完全に削除され、レイアウトに影響を与える可能性があります。

レイアウトに影響を与えずにリストの可視性を変更したい場合は、div をラッパーとして使用してから、その可視性プロパティを変更できます。

<div id="wrapper">          
    <asp:ListBox ID="ListBox3" runat="server"></asp:ListBox>            
</div>
<asp:Button ID="btnShow" runat="server" Text="Button" />
<asp:Button ID="btnHide" runat="server" Text="Button" />

ASPX を変更して、リスト ボックスを含む div 要素の可視性プロパティを切り替えます。

if (!IsPostBack)
{
    btnHide.Attributes.Add("onmouseout", "this.style.backgroundColor='Blue';wrapper.style.visibility='hidden'");
    btnShow.Attributes.Add("onmouseover", "this.style.backgroundColor='Red';   wrapper.style.visibility='visible'");
}
于 2009-05-05T01:12:24.943 に答える