show()之后的jQuery更改事件问题 [英] jQuery change event issue after show()

查看:142
本文介绍了show()之后的jQuery更改事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML文档带有按钮添加新"和隐藏的div(样式=显示:无;"),并带有其他字段.当用户单击按钮添加新" div时可见:

I have html document with button 'Add new' and hidden div (style='display: none;') with additional fields. When user click on button 'Add new' div become visible:

<script>
$(document).ready(function () {
    $('#add_new').click(function () {
            $('#add_new_panel').show();
            $(this).hide();
        });

    $('#selected_file').change(function(){
            alert(44);
        });
});
</script>

<div id="add_new_panel" style="display: none;">
    <input type="file" id="selected_file" name="testFile" />
</div>

问题是,当我在输入字段中选择文件时,此字段上的jQuery change事件永远不会触发.如果我删除style ='display:none;'从add_new_panel div可以正常工作.但我需要隐藏此div,直到用户未单击按钮.我怎样才能做到这一点?也许我可以将更改事件处理程序与其他代码绑定?

The problem is when I choose file in input field jQuery change event on this field never fires. If I remove style='display: none;' from add_new_panel div it works correctly. But I need hide this div until user doesnt click on button. How can I do this? Maybe I can bind change event handler with another code?

P.S.在另一页上,这与'display:none;'完美配合​​.

P.S. On the other page this works perfectly with 'display: none;'.

对不起,我的英语不好.谢谢.

Sorry for my bad english. Thanks.

推荐答案

问题出在输入文件字段的名称中.我删除了名称属性,现在可以使用了. 花了2个小时一无所有.请问:).

The problem was in name of input file field. I remove name attribute and now it works. 2 hours was spent for nothing. Excuse me :).

这篇关于show()之后的jQuery更改事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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