0

我有这个问题:我有这个代码

if(ext!="rar") {
$('#myform').trigger('click');
}

如果所选文件的文件扩展名不是rar,则文件输入应再次打开窗口以选择另一个文件,但此代码似乎不起作用。我应该怎么办?

4

2 回答 2

0
$("#btn").click(function()
{    
    var fu = $("#fu");
    var ext = /[^.]+$/.exec(fu.val());
    if (ext!="rar")
    {
        fu.trigger("click");
    }
});

http://jsfiddle.net/tugpM/1/

于 2013-08-16T22:18:14.013 回答
-1

Assuming that your form tag has the id myform, what you have done just triggers a click on the form (not even on the submit button of the form). Without the HTML, it is not possible to know what you are triggering the click on.

What you need to do is trigger the click on the submit button

$('#mysubmitbutton').click();

or trigger a form submit:

$('#myform').submit();
于 2013-08-16T22:15:13.747 回答