Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 表单提交事件未捕获SelectedIndex是否已更改?_Javascript_Jquery_Html_Asp.net_Forms - Fatal编程技术网

Javascript 表单提交事件未捕获SelectedIndex是否已更改?

Javascript 表单提交事件未捕获SelectedIndex是否已更改?,javascript,jquery,html,asp.net,forms,Javascript,Jquery,Html,Asp.net,Forms,我有一个按钮和一个下拉列表 我有一个剧本: $("form").submit(function (e) { $('#divOverlay').show(); }); 我的目标是: 提交表单时,我需要显示“加载div”: 问题: <html > <head> ... </head> <body> <div id='divOverlay'> ...

我有一个
按钮
和一个
下拉列表

我有一个剧本:

$("form").submit(function (e)
    {
        $('#divOverlay').show();
        });
我的目标是:

提交表单时,我需要显示“加载
div
”:

问题:

<html  >
<head>
 ...     
</head>
<body>
    <div id='divOverlay'>  
       ...
    </div>

        <form id="form1" runat="server"  >
            <asp:Button runat="server" Text="sssssss"/>
        <asp:DropDownList runat="server" OnSelectedIndexChanged="OnSelectedIndexChanged" AutoPostBack="True">
            ...
        </asp:DropDownList>

        </form>


        <script type="text/javascript">
            $(function()
                {
                    $("form").submit(function (e)
                    {
                            $('#divOverlay').show();
                    });
                });

        </script>
</body>
</html>
当我按下按钮时,会显示div(闪烁一秒钟的灰色div):

但当我更改dropdownlist上的索引时:

<asp:DropDownList runat="server" OnSelectedIndexChanged="OnSelectedIndexChanged" AutoPostBack="True">
    <asp:ListItem Value="a"> a</asp:ListItem>
        <asp:ListItem Value="b">b</asp:ListItem>
</asp:DropDownList>
能否显示发送到服务器的两个请求之间的差异?**

右侧是索引更改时,左侧窗格用于按钮按下


我猜自动回写行为是通过javascript提交表单,并调用
\uu doPostBack()
,这不会触发提交事件

你可以尝试:

<asp:DropDownList onchange="$('#divOverlay').show();" runat="server" OnSelectedIndexChanged="OnSelectedIndexChanged" AutoPostBack="True">

不确定,听起来像是DDL的回发和形式r的不同

无论如何,我建议您只需从DDL中删除自动回发,并添加一个客户端onchange,在那里您可以显示灰色div,然后手动回发服务器端onselect,如下所示:
或者只是$(“form”).submit()

不确定这是否有帮助,但这对我来说很有效。我可以在两个事件中显示叠加div

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript">
        $(document).ready(function () {
            $("form").submit(function (e) { 
                alert("Submit");
            });
            $("#dropdown").change(function (e) {
                alert("Hi");
            });
        });

    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Button runat="server" ID="submitbutton" Text="submit"/>
    <asp:DropDownList ID="dropdown" ClientIDMode="Static"  runat="server" AutoPostBack="True"  OnSelectedIndexChanged="OnSelectedIndexChange"/>
</asp:Content>

$(文档).ready(函数(){
$(“表格”)。提交(职能(e){
警报(“提交”);
});
$(“#下拉列表”).change(函数(e){
警报(“Hi”);
});
});

有一个ASP.NET的方法:,它允许您在每次提交HtmlForm时运行JavaScript语句

ClientScript.RegisterOnSubmitStatement(this.GetType(), "divOverlayShow", "$('#divOverlay').show();");

也许这会有帮助:@Johan尝试了document.ready和nother,但仍然不起作用。这似乎是相关的:也许这会有帮助?整个目的是添加一个脚本,显示给定站点的div,这意味着-不要接触html并用纯JS解决它。您的解决方案需要更改每个页面的功能性/代码我想我在这里遗漏了一些东西Royi,您无论如何都在做这个$(“表单”).submit(函数(e){$('#divOverlay').show()});,你为什么不能在那里加上几行呢?抱歉,这是在一个单独的JS文件(JS file).p.s.上完成的。我已经找到了解决办法。submit是表单对象的javascript方法。它也是用户提交表单时触发的事件。但通过代码提交表单时不会触发。看,这是工作。非常感谢。我将研究它背后生成的JS。奇怪,但
$(“form”).attr('onsubmit','alert(1);')确实有效。附加JS事件处理程序时不工作。。。。