2

我的多视图控件中有 3 个视图。我想使用javascript更改客户端多视图的activeviewindex。我做不到。帮助将不胜感激。我的代码是:

<asp:Panel runat="server" ID="multiviewContainer" CssClass="multiviewContainer">
    <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
        <asp:View ID="View1" runat="server">
            View 0
        </asp:View>
        <asp:View ID="View2" runat="server">
            View 1
        </asp:View>
        <asp:View ID="View3" runat="server">
            View 2
        </asp:View>
        <asp:View ID="View4" runat="server">
            View 3
        </asp:View>
    </asp:MultiView>
</asp:Panel>
4

1 回答 1

1

MultiView 是一个服务器端控件,并不意味着要在客户端进行修改,因此即使在技术上可以更改活动索引客户端,您也可能不应该这样做。所以我认为没有人会为这个问题提供任何“好的”答案。为什么不使用 jQuery?

<script type="text/javascript">

    function ChangeActiveIndex(index) {
        $('div').hide(); // change this selector to be more specific
        $('#div' + index).show();
    }

</script>

<div id="div1">View 1</div>
<div id="div2">View 2</div>
<div id="div3">View 3</div>

<span onclick="ChangeActiveIndex(1);">Show View 1</span>
<span onclick="ChangeActiveIndex(2);">Show View 2</span>
<span onclick="ChangeActiveIndex(3);">Show View 3</span>

如果需要,您还可以在后面的代码中修改它们:

<div id="div1" runat="server">View 1</div>

div1.Attributes.Add("class", "make-a-class-display:none-or-display:inline")
于 2013-01-15T21:04:58.270 回答