出于某种原因,jquery不会在VB项目上运行

时间:2018-05-31 05:04:38

标签: javascript jquery asp.net vb.net

这个jQuery函数在这个VB项目中由于某种原因不起作用,但是在另一个VB项目中工作/运行。

不工作

<%@ Page Title="Dealer Allocation Watchlist (Marketing)" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="05055.aspx.vb" Inherits="_05055" %>

<%@ Register Src="Usercontrols/wucDatepicker.ascx" TagName="wucDatepicker" TagPrefix="uc1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="_titleContent" runat="Server">
    <style type="text/css">
        .style3 {
            width: 500px;
        }

        .HeaderCSS {
            color: Snow;
            background-color: Crimson;
            font-size: medium;
            border: solid 1px salmon;
            font-weight: bold;
            cursor: pointer;
        }

        .HeaderSelectedCSS {
            color: Snow;
            background-color: OrangeRed;
            font-weight: bold;
            font-style: italic;
            cursor: pointer;
        }
    </style>
    <script src="Scripts/jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
        alert('yo!');
        $(document).ready(function () {
            $('#<%=lblNoRecords.ClientID%>').css('display', 'none');

            $('#<%=txtSearch.ClientID%>').keyup(function (e) {
                $('#<%=lblNoRecords.ClientID%>').css('display', 'none');
                $("#<%=grid.ClientID%> tr:has(td)").hide();

                var iCounter = 0;
                var sSearchTerm = $('#<%=txtSearch.ClientID%>').val();

                if (sSearchTerm.length == 0) {
                    $("#<%=grid.ClientID%> tr:has(td)").show();
                    return false;
                }
                $("#<%=grid.ClientID%> tr:has(td)").children().each(function () {
                    var cellText = $(this).text().toLowerCase();
                    if (cellText.indexOf(sSearchTerm.toLowerCase()) >= 0) {
                        $(this).parent().show();
                        iCounter++;
                        return true;
                    }
                });
                if (iCounter == 0) {
                    $('#<%=lblNoRecords.ClientID%>').css('display', '');
                }
                e.preventDefault();
            });
        });
        </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="_mainContent" runat="Server">

        <table>
        <tr>
            <td colspan="2" style="text-align: left;">
                <asp:Label ID="Label1" runat="server" Text="Dealer Credit Approval Watchlist (Marketing)" Font-Bold="True" Font-Names="Verdana" Font-Size="Larger" ForeColor="White"></asp:Label>
            </td>
        </tr>
            </table>
     <asp:Panel ID="Panel3" runat="server" Height="20px">
        </asp:Panel>
        <asp:Label runat="server" ForeColor="White" Font-Names="Verdana">Search results: </asp:Label>
    <asp:TextBox ID="txtSearch" runat="server" onkeyup="search()"></asp:TextBox>
            &nbsp;
        <asp:Button ID="btnSubmit" runat="server" Text="Search" />

    <asp:Panel ID="Panel2" runat="server" Height="20px">
        </asp:Panel>
    <div>

    <asp:Label ID="Label2" Text="CLICK ON 'DEALER CODE' TO NAVIGATE TO APPROVAL INTERFACE" runat="server" Font-Names="Verdana" ForeColor="white" Font-Size="Larger"></asp:Label>
    </div>
        <asp:Panel ID="Panel1" runat="server" ScrollBars="Vertical" Height="300px" Width="90%">
<asp:GridView ID="grid" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" ShowFooter="True" Font-Names="Verdana" Font-Size="X-Small" AllowSorting="True">
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#7C6F57" />
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" Font-Names="Verdana" Font-Size="XX-Small" />
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" Font-Names="Verdana" Font-Size="XX-Small" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#E3EAEB" Font-Names="Verdana" Font-Size="XX-Small" />
        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F8FAFA" />
        <SortedAscendingHeaderStyle BackColor="#246B61" />
        <SortedDescendingCellStyle BackColor="#D4DFE1" />
        <SortedDescendingHeaderStyle BackColor="#15524A" />
        <Columns>
            <asp:TemplateField HeaderText="Dealer Code">
                <ItemTemplate>

                    <asp:LinkButton ID="lblDealerCode" runat="server" Text='<%# Eval("DealerCode") %>' OnClick="lblEdit_Click"></asp:LinkButton>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" Width="10%" />
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>

            <asp:templatefield headertext="Dealer Name">
                <itemtemplate>

                    <asp:Label ID="lbldealername" runat="server" text='<%#Eval("DealerName") %>'></asp:Label>
                </itemtemplate>
                <headerstyle horizontalalign="left" width="15%" />
                <itemstyle horizontalalign="left" />
            </asp:templatefield>

            <asp:TemplateField HeaderText="VH Allocated Amount">
                <ItemTemplate>
                    <asp:Label ID="lblAmount_VH" runat="server" Text='<%# CustomCDBL(Eval("Amount_VH")).ToString("#,###,###,##0") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Right" Width="10%" />
                <ItemStyle HorizontalAlign="Right" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="MX Allocated Amount">
                <ItemTemplate>
                    <asp:Label ID="lblAmount_MX" runat="server" Text='<%# CustomCDBL(Eval("Amount_MX")).ToString("#,###,###,##0") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Right" Width="10%" />
                <ItemStyle HorizontalAlign="Right" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="OB Allocated Amount">
                <ItemTemplate>
                    <asp:Label ID="lblAmount_OB" runat="server" Text='<%# CustomCDBL(Eval("Amount_OB")).ToString("#,###,###,##0") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Right" Width="10%" />
                <ItemStyle HorizontalAlign="Right" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="SP Allocated Amount">
                <ItemTemplate>
                    <asp:Label ID="lblAmount_SP" runat="server" Text='<%# CustomCDBL(Eval("Amount_SP")).ToString("#,###,###,##0") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Right" Width="10%" />
                <ItemStyle HorizontalAlign="Right" />
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
            </asp:Panel>
    <asp:Label ID="lblNoRecords" Text="No records to display" runat="server" ForeColor="red" Font-Size="Medium" Font-Bold="true"></asp:Label>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
    </asp:Content>

工作

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_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>Search GridView Data</title>
    <style type="text/css">
    body
    {
        font-family: Arial;
        font-size : 10pt;
    }
    .links
    {
        font-weight: bold;
    }
    </style>

    <script type="text/javascript" src="Scripts/jquery-1.7.1.min.js"></script>

        <script type="text/javascript" language="javascript">
        $(document).ready(function() {
            $('#<%=lblNoRecords.ClientID%>').css('display','none');

            $('#<%=txtSearch.ClientID%>').keyup(function(e)
            {
                $('#<%=lblNoRecords.ClientID%>').css('display','none');
                $("#<%=gdRows.ClientID%> tr:has(td)").hide();

                var iCounter = 0;
                var sSearchTerm = $('#<%=txtSearch.ClientID%>').val();

                if(sSearchTerm.length == 0)
                {
                  $("#<%=gdRows.ClientID%> tr:has(td)").show(); 
                  return false;
                }
                $("#<%=gdRows.ClientID%> tr:has(td)").children().each(function() 
                {
                    var cellText = $(this).text().toLowerCase();
                    if(cellText.indexOf(sSearchTerm.toLowerCase()) >= 0)
                    {    
                        $(this).parent().show();
                        iCounter++;
                        return true;
                    } 
                });
                if(iCounter == 0)
                {
                    $('#<%=lblNoRecords.ClientID%>').css('display','');
                }
                e.preventDefault();
            })
        })
        </script>

</head>
<body>
    <form id="form1" runat="server">
        <br />
        <br />
        Search Text :
        <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
        &nbsp;
        <asp:Button ID="btnSubmit" runat="server" Text="Search" />
        <br /><br />
        <input id="Button1" type="button" onclick="readySearch()" value="button" />
        <br />
        <asp:GridView ID="gdRows" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
            BorderWidth="1px" CellPadding="6" Font-Names="Arial" Font-Size="Small" GridLines="None"
            ForeColor="Black" Width="36%">
            <FooterStyle BackColor="Tan" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" HorizontalAlign="Left" />
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
            <RowStyle HorizontalAlign="Left" />
        </asp:GridView>
        <asp:Label ID="lblNoRecords" Text="No records to display" runat="server" ForeColor="red"></asp:Label>
    </form>
</body>
</html>

我不知道为什么。请帮忙。此外,当我只是简单地显示一个警告框时,它就像一个魅力。我不知道这里有什么问题,因为该功能在另一个项目中有效。

2 个答案:

答案 0 :(得分:0)

这是愚蠢的。我把脚本放在错误的内容持有者身上。

答案 1 :(得分:0)

工作的javascript函数是onclick="readySearch()"

无法使用的标记是onkeyup="search()"

错误是说javascript函数search()不存在。它不存在或拼写错误,或应为readySearch()