简体   繁体   English

使用JavaScript验证来使用jQuery

[英]Use javascript validation to use jQuery

Hi I'm kind of new to Javascript and jQuery, what I want to do is a suggestion box that opens when the user clicks on a bottom div or button, and the div appears, so to do that I will use jQuery, the problem is that this will only be shown to logged users. 嗨,我是Java和jQuery的新手,我想做的是一个建议框,当用户单击底部的div或按钮时,该建议框会打开,并且div出现,因此我将使用jQuery,即问题是,这只会显示给已登录的用户。 I know how to validate a session state with Javascript, so here comes my question, how can I make this thing to only show to logged in users using only jQuery, or using a Javascript? 我知道如何使用Javascript验证会话状态,所以这是我的问题,如何使此内容仅显示给仅使用jQuery或Javascript的登录用户? Can I use both? 我可以同时使用吗?

Note: I'm using .ASPX with C# on Visual Studio, this file uses a MasterPage 注意:我在Visual Studio上使用带有C#的.ASPX,此文件使用MasterPage

Here is the jQuery code, animations work kind of lame but it works as intended: 这是jQuery代码,动画虽然有点la脚,但可以按预期工作:

<script>
    $(function () {
        $("#chat_content").hide();
        $("#chat_content").css('bottom:-280px;');
        $("#chat_header").click(function () {
            $("#chat_content").toggle(250);
            $("#chat_content").animate({bottom:'0'});
        });
    });
</script>

Here the HTML, still no backcode on C#, that I will do later 在这里,HTML,仍然没有C#的回码,我以后会做

<asp:Content ContentPlaceHolderID="chat_on" ID="cajadechat" runat="server">
    <div id="chat_header">
        <label id="bar_content_lbl">Chat en Línea</label>
        <img src="imagenes/botones/icono chat.png" id="chat_icon" />
    </div>
    <div id="chat_content">
        <span id="chat">
        En este momento no estamos conectados al Chat. Pero déjanos un mensaje y muy pronto nos contactaremos contigo. ¡Gracias!</span><br /><br />
        Su nombre*:<br />
        <asp:TextBox ID="txt_nombrechat" CssClass="chattext" runat="server" ></asp:TextBox><br />
        Su correo*:<br />
        <asp:TextBox ID="txt_correochat" CssClass="chattext" runat="server" ></asp:TextBox><br />
        Su pregunta*:<br />
        <asp:TextBox TextMode="MultiLine" CssClass="chatarea" runat="server" ></asp:TextBox><br />
        <asp:Button ID="btn_chat" CssClass="chatbutton" runat="server" Text="ENVIAR" />
    </div>
</asp:Content>

And here the corresponding CSS 这是对应的CSS

#contacto_ebook{
    position:fixed;
    right:150px;
    bottom:0;
    z-index:40;
    font-family: EuroStileTRegExt;
}
#chat_header{
    height:10px;
    width:260px;
    padding:10px 0 10px;
    background-color:#3a80cb;
    border-top-right-radius: 4px;
    border-top-left-radius: 4px;
}
#chat_header:hover{
    background-color:#499cf5;
    cursor:pointer;
}
#chat_content{
    height:280px;
    width:240px;
    background-color:#ffffff;
    text-align:left !important;
    padding:5px 10px 0 10px;
}
.chatbutton,.chattext,.chatarea{
    border-radius:3px;
    font-size:14px !important;
}
.chatbutton{
    height:40px;
    width:100%;
    margin-top:4px;
    cursor:pointer;
    color:#ffffff;
    box-shadow:none;
    background-color:#3a80cb;
    border:none; 
}
.chatbutton:hover{
    background-color:#499cf5;
}
.chattext,.chatarea{
    width:98%;
}
.chatarea{
    resize:none;
    outline-color:#3a80cb;
    height:52px;
}
#bar_content_lbl{
    color:#ffffff !important;
    font-size:14px !important;
    cursor:pointer;
    float:left;
    margin-left:10px;
}
#chat_icon{
    width:14px;
    height:14px;
    float:right;
    margin-right:10px;
}
#chat{
    text-align:justify !important;
    font-size:12px !important;
}

How are you showing that the user is logged in? 您如何显示用户已登录? Is this an MVC application where you would be able to pass whether or not the user is logged in to the view? 这是一个MVC应用程序,无论用户是否登录到视图,您都可以通过该应用程序? Then you would simply have to check a certain value on the DOM for whether or not the user is logged in and then display. 然后,您只需要检查DOM上的某个值即可确定用户是否已登录然后显示。

Modern browsers also have access to local storage, so you could store whether or not the user is logged in there, then check with javascript / jQuery and display accordingly. 现代浏览器还可以访问本地存储,因此您可以存储用户是否登录到本地存储,然后使用javascript / jQuery检查并进行相应显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM