문제

"OnMouseOver"이벤트를 사용하여 ListBox가 나타나고 사라지게합니다. 나는 asp.net과 상당히 새롭고 아직 JavaScript를 쓰고 싶지 않습니다. 다음 코드를 사용하려고 노력하고 있으며 IT의 색상 변경 부분이 작동하지만 ListBox 가시성은 작동하지 않습니다.

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'");
        }

나는 "포스트 백"이 있거나없는이 코드를 시도했지만 여전히 운이 없습니다. 내 코드가 어디에서 실패했는지 보는 사람이 있습니까?

고맙습니다,

DFM

도움이 되었습니까?

해결책

노력하다:

    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" />

목록 상자가 포함 된 DIV 요소의 가시성 속성을 전환하려면 ASPX를 수정하십시오.

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'");
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top