0

编码:

$("#pitch_image_path_browseiser").live("change",function(){

    $("#pitch_image_path_form").live("submit",function(e){
        alert("sdfdsf");
            this.submit();

        });


    });

现在调用更改事件,但不调用表单提交事件。

未调用实时提交事件。

4

7 回答 7

1

亲爱的 renishkhunt 请试试这个代码。这对我来说完全有帮助。

$("#pitch_image_path_browseiser").live("change",function(){
    $("#pitch_image_path_form").ajaxSubmit({ success: function(){ 
            alert("sdfdsf");
     } });
});

请检查此链接这是教程

于 2013-10-25T04:34:23.200 回答
1

submit当更改事件触发时,您拥有的代码将附加到事件中。它不会触发任何事件

您需要直接触发提交

$("#pitch_image_path_browseiser").live("change",function(){
    $("#pitch_image_path_form")[0].submit();});

如果你想对提交事件做一些事情,你可以在提交中添加一个事件。请注意,该事件在信息发送到服务器之前触发。提交完成时没有事件,因为提交会重新加载页面(或另一个页面)

 $(function(){
     $("#pitch_image_path_browseiser").live("change",function(){
        $("#pitch_image_path_form")[0].submit();
     });

      $("#pitch_image_path_form").live("submit",function(){
         //do what ever you need to do here
         //$.post(url);
      });
  });
于 2013-10-24T12:47:41.847 回答
0

我做了一些更改,因为在您的代码中,submit每次#pitch_image_path_browseiser更改时都会附加事件。,告诉我它是否能解决您的问题:

$("#pitch_image_path_browseiser").die('change').live('change',function(){

$("#pitch_image_path_form").unbind('submit').bind("submit",function(e){
    alert("sdfdsf");
        //this function is already called ONLY when form is submitted...
       // this.submit();

    });

});

但是在这种情况下,您必须等待表单提交...如果要提交表单,请使用或添加:

$("#pitch_image_path_form").submit();

所以如果我明白你不想这样做,我认为好的方法是:(我一直live打电话)

 $("#pitch_image_path_form").unbind('submit').bind("submit",function(e){
    alert("sdfdsf");
});
$("#pitch_image_path_browseiser").die('change').live('change',function(){
   $("#pitch_image_path_form").submit();
});
于 2013-10-24T12:42:53.867 回答
0

jQuery.live()自 jQuery 1.9 起不可用。你在运行什么版本?

无论如何,请改用.on()

$(document).on('change', '#pitch_image_path_browseiser', function() { 
    $(document).on('submit', '#pitch_image_path_form', function(e){
       alert("sdfdsf");
       $("#pitch_image_path_form").submit();
    });
});

希望有帮助。

于 2013-10-24T12:43:21.750 回答
0

您是否尝试这样做:

$("#pitch_image_path_browseiser").live("change",function(){
    $("#pitch_image_path_form").submit();
});

这意味着当触发“更改”时,提交表单。

于 2013-10-24T12:44:36.990 回答
0

只需调用 $("#pitch_image_path_form").submit() 而不是第二个 .live

但是您需要在其他地方指定 .live 方法

$("#pitch_image_path_browseiser").live("change",function(){
    $("#pitch_image_path_form").submit();
});

$("#pitch_image_path_form").live("submit",function(e){
    alert("sdfdsf");
});
于 2013-10-24T12:46:14.267 回答
0

this.submit()提交时正在调用...我想您想触发它以显示警报

尝试:

```

$(document).ready(function() {

  $("#pitch_image_path_browseiser").die('change').live('change',function(){
    $("#pitch_image_path_form").unbind('submit').bind("submit",function(e){
        alert("sdfdsf");
    });
  });

  $("#pitch_image_path_form").trigger('submit');

});
于 2013-10-24T12:47:12.833 回答