English 中文(简体)
j 提交预防文件的质量不可行
原标题:jQuery on submit preventDefault() does not works

我有html表格,提交纽芬兰文和材料控制:

<form action="/Profile/UploadFile" enctype="multipart/form-data" method="post" onsubmit="OnUploadSubmit(this)"> 

在卸载功能方面,情况如下:

  if (e.files[0].size > 5000000) {
        $( #upload_error ).css( display ,  block );
        $( #upload_error ).text( The file size is too large for upload )
        e.preventDefault();
        return false;
    }

    var files = e.files;
    var ext = $( #file_uploader ).val().split( . ).pop().toLowerCase();
    if ($.inArray(ext, [ jpeg ,  jpg ,  png ]) == -1) {
        $( #upload_error ).css( display ,  block );
        $( #upload_error ).text( Only, jpg, jpeg, png is allowed );
        e.preventDefault();
        return false;
    }
    return true;
}

e. 防止违约和返还不实;不采用工作方式提交。

没有人知道我的问题是什么?

Thanks

最佳回答

首先,由于你不把事件标本变为功能,你可以以此方式防止过失。

onsubmit="return OnUploadSubmit(this)"

i 建议:

补充说明和删除:

<form id="upload" action="/Profile/UploadFile" enctype="multipart/form-data" method="post"> 

j 质量:

$(function(){ // Document Ready

        $( #upload ).submit(function(e){

        e.preventDefault();
         if (e.files[0].size > 5000000) {
                $( #upload_error ).css( display ,  block );
                $( #upload_error ).text( The file size is too large for upload )
            }

            var files = e.files;
            var ext = $( #file_uploader ).val().split( . ).pop().toLowerCase();
            if ($.inArray(ext, [ jpeg ,  jpg ,  png ]) == -1) {
                $( #upload_error ).css( display ,  block );
                $( #upload_error ).text( Only, jpg, jpeg, png is allowed );
            }
        }

    });

});
问题回答

您对上载荷的定义是否包含一个参数? 否则,即假冒不会奏效。

您是否尝试了<代码>onsubmit=“return OnUpload Submit (this);,而不是onsubmit=“OnUpload Submit(this)”?

我想你需要<代码>onsubmit=“return OnUploadSubmit(this)”





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签