简体   繁体   English

仅选择一个Fileupload事件

[英]Select only one onchange event of Fileupload

I have an asp.net page with master page. 我有一个带有母版页的asp.net页。 I have a fileupload control on child(having master page) page. 我在子页面(具有母版页)上有一个文件上传控件。 I am using jquery's change event for fileupload on child page. 我在子页面上将jquery的change事件用于fileupload。 now i want to disable fileupload control for some reasons from master page. 现在我出于某些原因希望从母版页禁用文件上传控制。 so i am using this script. 所以我正在使用这个脚本。

 function blockFileUpload() {
                $('input[type=file]').change(function () {
                    $('input[type=file]').val('');
                    alert("You Can Not Upload File. Files Storage (50 MB) Limit Reached. ");
                    $('input[type=file]').preventDefault();
                    return false;
                });
            }

Now when file upload change event is called both event work simultaneously. 现在,当文件上传更改事件被调用时,两个事件将同时工作。 so how can i disable child page's change event and hook only master page's onchange event. 因此,我如何禁用子页面的更改事件并仅挂接母版页的onchange事件。

Thanx in advance... 提前感谢...

Unbind all your change events first and then assign your new change event. 首先取消绑定所有更改事件,然后分配新的更改事件。 For eg: 例如:

function blockFileUpload() {
                $('input[type=file]').unbind('change');
                $('input[type=file]').change(function () {
                    $('input[type=file]').val('');
                    alert("You Can Not Upload File. Files Storage (50 MB) Limit Reached. ");
                    $('input[type=file]').preventDefault();
                    return false;
                });
            }

The code $('input[type=file]').unbind('change'); 代码$('input[type=file]').unbind('change'); unbinds all the change event related to the file inputs. 取消绑定与文件输入有关的所有change事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM