尝试上传单击图像的文件时出现问题

时间:2013-09-28 05:19:40

标签: jquery html forms file upload

因此,当我点击输入类型图像时,我尝试打开上传文件输入。当我单击图像时,上传文件窗口出现,但是当我选择一个文件时,它不会加载(名称不会显示而不是“没有选择文件”)。此外,如果单击表单上的信息并单击图像按钮,则会清空先前的输入。

当我点击上传文件而不是图像时,一切正常,没有任何内容被清空,图像正确加载。这是代码,希望你能帮助我:

HTML表单:

        <form class='register-form-user-frmt' action='' method='post' enctype="multipart/form-data" >
            <span class='register-form-user-email'> 
                E-mail: <br> <input type='email' name='register-form-user-email' />
            </span>
            <span class='register-form-user-name'> 
                On-page name: <br> <input type='text' name='register-form-user-name' />
            </span>
            <span class='register-form-user-password'> 
                Password: <br> <input type='password' name='register-form-user-password' />
            </span>
            <span class='register-form-user-password-repeat'> 
                Check password: <br> <input type='password' name='register-form-user-password-repeat' />
            </span>
            <span class='register-form-user-image-upload-hidden'> 
                <input type='file' id='register-form-user-image-upload-hidden' name='photo'/>
            </span>
            <span class='register-form-user-submit'> 
                <input type='submit' name='register-form-user-submit' value='Submit' />
            </span>
            <span class='register-form-user-image-button'> 
                Upload image: <br> <input type='image' name='register-form-user-image-user-button' src='images/camera upload logo.png' />
            </span>
        </form>

JQuery的:

$(document).ready(function() {
$('.register-form-user-image-button').click(function() {
    $('#register-form-user-image-upload-hidden').click();
});
});

感谢。

1 个答案:

答案 0 :(得分:-1)

您可以使用此

<span class='register-form-user-image-button'> 
    Upload image: <br> <input type='file' name='register-form-user-image-user-button' src='images/camera upload logo.png' />
</span>

在此之后,如果您的文件类型是jpg,bmp等,请创建php文件以进行过滤。Here是参考。这将没有jquery。