MultiView 和 JavaScript(或 jquery)工作

发布于 2024-09-10 15:25:35 字数 1956 浏览 3 评论 0原文

我如何在 javascript 或 jquery 中获得多视图?

下面的代码总是返回 null :(Javascript)

var MultiView = document.getElementById("MultiView1");

并且下面的代码不是 null 但不起作用:(jquery)

var MultiView = $("*[id$='TextBox1']"); 

这是怎么回事?

你能给我一个使用 JavaScript 或 Jquery 检查 ActiveViewIndex 的示例代码吗?

由于评论,我添加了以下代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Keyup._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>

    <%--    <script src="JQuery/jquery-1.4.1.js" type="text/javascript"></script>--%>
                <script type="text/javascript">

                    document.onkeyup = onkeyupOfDocument;

                    function onkeyupOfDocument(evt) {
                        var evt = evt || window.event;
                        //alert(evt.keyCode);
                        //var MultiView = $("*[id$='TextBox1']"); 
                        var MultiView = document.getElementById("MultiView1");
                        alert(MultiView);
                    }

        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                <asp:View ID="View1" runat="server">
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </asp:View>
                <asp:View ID="View2" runat="server">
                </asp:View>
            </asp:MultiView>
        </div>
        </form>
    </body>
    </html>

提前感谢

how can i get multiview in javascript or jquery ?

below code always returns null : (Javascript)

var MultiView = document.getElementById("MultiView1");

and below code is not null but not work :(jquery)

var MultiView = $("*[id$='TextBox1']"); 

what is the going on about that?

can u give me plz a sample code for checking ActiveViewIndex With JavaScript or Jquery!

i added the below code because of comment :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Keyup._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>

    <%--    <script src="JQuery/jquery-1.4.1.js" type="text/javascript"></script>--%>
                <script type="text/javascript">

                    document.onkeyup = onkeyupOfDocument;

                    function onkeyupOfDocument(evt) {
                        var evt = evt || window.event;
                        //alert(evt.keyCode);
                        //var MultiView = $("*[id$='TextBox1']"); 
                        var MultiView = document.getElementById("MultiView1");
                        alert(MultiView);
                    }

        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                <asp:View ID="View1" runat="server">
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </asp:View>
                <asp:View ID="View2" runat="server">
                </asp:View>
            </asp:MultiView>
        </div>
        </form>
    </body>
    </html>

thanks in future advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2024-09-17 15:25:35

抱歉耽误了您的时间,但这就是您正在寻找的内容:

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            var activeViewIndex = $('.multiviewContainer').attr('activeKey');

            alert(activeViewIndex);

        });
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

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

</asp:Content>

以及背后的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string activeView = MultiView1.ActiveViewIndex.ToString();
        multiviewContainer.Attributes.Add("activeKey", activeView);
    }
}

Sorry for the delay but here is what you are looking for :

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            var activeViewIndex = $('.multiviewContainer').attr('activeKey');

            alert(activeViewIndex);

        });
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

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

</asp:Content>

and code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string activeView = MultiView1.ActiveViewIndex.ToString();
        multiviewContainer.Attributes.Add("activeKey", activeView);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文