开发者

If statement to display a div in different place in aspx page

ASP.NET4

This is my aspx page, which has a css file defining #div1, #div2, #div3 styles, and javascript code to have some dynamic change with divs. My question is in a page, there can't be 2 same ids. So div2 can pass here. What's the best way to work around this? Having a div2a, div2b, and in css file - having #div2a, #div2b using same style? And having javascript to select both div2a, div2b? Please advise.

<form id="form1" runat="server">
    <div>
        <%if (condition) { %>
        <div id="div1"> ... </div>
      开发者_JAVA技巧  <%} %>
        <%else { %>
        <div id="div2"> ... </div>
        <%} %>
        ...
        ...

        <%if (condition) { %>
        <div id="div2"> ... </div>
        <%} %>
        <%else { %>
        <div id="div3"> ... </div>
        <%} %>
    </div>
</form>


You can use "class" attribute to define same style. You can have more elements using the same class attribute value and it's still xhtml valid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜