【问题标题】:change jQuery don't work [duplicate]更改 jQuery 不起作用 [重复]
【发布时间】:2013-06-09 13:47:12
【问题描述】:

我有这个代码:

        $(".input_photo").click(function() {

            $.post("ajax/imagefile.html", function(img){
                complete: $(".bp_load").fadeIn(0).html(img);
            });
        });

Imagefile 是一个简单的 HTML 页面,其中包含 ID 为 imageform 的表单和输入类型文件。

我还有另一个代码:

            $('#photoimg').live('change', function(){
                $("#imageform").ajaxForm({
                    target: '.preview'
                }).submit();
            });

我在网上搜索,了解到live 已弃用,我已更改为on,但它不起作用。输入类型文件改变了,但没有触发事件。

【问题讨论】:

  • 您使用的是哪个版本的 jQuery?您是否收到任何控制台错误?
  • 你使用什么 jQuery 版本? $.on() 在 1.7 中添加。
  • 据我所知,此事件似乎仅限于 元素。stackoverflow.com/questions/1443292/…
  • @user2465422 live() 已从 1.9.x 中删除,因此请使用 .on() 委托

标签: jquery html ajax events


【解决方案1】:

使用.on() 等价于:{delegate syntax}

$(document).on('change', '#photoimg',function(){
                $("#imageform").ajaxForm({
                    target: '.preview'
                }).submit();
            });

【讨论】:

  • 烤的太棒了,太棒了!!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-25
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多