jQuery的不能与母版页的工作 [英] jQuery not working with Master Page

查看:169
本文介绍了jQuery的不能与母版页的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些片code这是独立工作的,但是当我与母版页添加它,它不工作。
我觉得jQuery的不更新小组工作,所以我删除了为好,但还是没有用。我相信这是一些问题,母版页。
任何人都可以看看,并给予任何建议。

I have some piece of code that was working individually but when I add it with the Master page, it is not working. I thought jQuery doesn't work with Update Panel, so I removed that as well, but still no use. I believe it is some problem with Master Page. Can anyone have a look and give any advice.

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

<asp:Content ID="HeaderContent" runat="server"     ContentPlaceHolderID="ContentPlaceHolder2"><b>Adhoc ArchivingTest  Page</b>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">


<script  src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {

        alert(2);
        function isDate(txtDate) {
            var currVal = txtDate;
            if (currVal == '')
                return false;

            //Declare Regex 
            //  var rxDatePattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
            var rxDatePattern = /^(\d{4})(\d{1,2})(\d{1,2})(\d{1,2})(\d{1,2})(\d{1,2})$/
            var dtArray = currVal.match(rxDatePattern); // is format OK?

            if (dtArray == null)
                return false;

            //Checks for mm/dd/yyyy format.
            //    dtMonth = dtArray[1];
            //   dtDay = dtArray[3];
            //   dtYear = dtArray[5];


            dtMonth = dtArray[2];
            dtDay = dtArray[3];
            dtYear = dtArray[1];
            ddhours = dtArray[4];
            ddminute = dtArray[5];
            ddseconds = dtArray[6];

            if (ddhours > 24)
                return false;
            if (ddminute > 60)
                return false;
            if (ddseconds > 60)
                return false;

            if (dtMonth < 1 || dtMonth > 12)
                return false;
            else if (dtDay < 1 || dtDay > 31)
                return false;

            else if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) && dtDay == 31)
                return false;
            else if (dtMonth == 2) {
                var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
                if (dtDay > 29 || (dtDay == 29 && !isleap))
                    return false;
            }
            return true;
        }

        $(function () {



            $('#txtname').blur(function (e) {
                alert(1);
                //     var GetValue = $('#txtname').val();


                var txtVal = $('#txtname').val();

                if (isDate(txtVal))

                    alert('Valid Date format');

                else

                    alert('Invalid Date format');
            });
        });

    });


</script>


<%--
<form id="form1" runat="server">--%>
    <div>
    <asp:Table ID="tblAdhocReq" runat="server" BackColor="White" 
            BorderColor="#999999" BorderStyle="None" BorderWidth="1px" cellpadding="3" 
            cellspacing="5" CssClass="contentheadlinemed" Font-Size="Smaller" 
            GridLines="Both" visible="true">
            <asp:TableRow>
       <asp:TableCell BackColor="#E0E0E0" HorizontalAlign="Right">ENTER REPORT VERSION DATE: : </asp:TableCell><asp:TableCell>
           <asp:TextBox ID="txtname"  runat="server" />
            &nbsp&nbsp<i>(Must enter in format YYYYMMDDHHMMSS)</i>  

        </asp:TableCell><asp:TableCell  BorderWidth="0"><asp:Label ID="Label2"  runat="server" Font-Italic="true" 
            Visible="false" ForeColor="red"/></asp:TableCell></asp:TableRow></asp:Table><%-- <asp:TextBox runat="server" ID="txtname"></asp:TextBox>

         <asp:TextBox runat="server" ID="TextBox1"></asp:TextBox>--%></div><%--</form>--%><%--</ContentTemplate>--%><%--</asp:UpdatePanel>--%><asp:Label id="ADDMsg" ForeColor="Red"  Runat="Server" Font-Bold="true"/>
<br />  

推荐答案

有可能是两件事情会在这里。

There are probably two things going on here.

第一个是你的控制很可能被分配唯一的ID是不一样的,你给他们的人。您可以使用Milind或ZiNNED的建议或类名称引用它们:

The first is that your controls are probably being assigned unique IDs that are not the same as the ones you gave them. You can use Milind or ZiNNED's suggestion or refer to them by class name:

<input type="text" id="txtname" class="text-name" runat="server" />

$(".text-name")

另外就是,既然你使用一个UpdatePanel,这些事件可能会尽快更新发生分离。为了说明这一点,使用。对()

$(document).on("blur", ".text-name", function (e) {
    alert(1);

    var txtVal = $(this).val();

    if (isDate(txtVal)) {
        alert('Valid Date format');
    } else {
        alert('Invalid Date format');
    }
});

这篇关于jQuery的不能与母版页的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆