繁体   English   中英

jQuery函数无法运行

[英]JQuery function does not operate

我有以下HTML结构

<div style="float: left; padding-top: 10px;">
            <a id="changeProfilePicture" class="linkOne" style="font-family: 'Ubuntu', sans-serif; color: #FA5882;" href="javascript:void">Change Profile Picture</a>
        </div>
        <div style="clear: both;"></div>
        <div style="display: none;" id="changeProfile">
            <div id="fSpace"></div>
            <form id="upload_form" enctype="multipart/form-data" method="post">
                <button id="openOpen">Select File</button>
                <input type="file" name="file1" id="file1"><br>
                <input type="button" value="Upload File" onclick="uploadFile()">
                <div id="fSpace"></div>
                <progress id="progressBar" value="0" max="100" style="width:300px;"></progress>
                <div id="fSpace"></div>
                <div id="status"></div>
            </form>
        </div>

因此,当我单击div changeProfilePicture时,div changeProfile会向下滑动。 当单击按钮openOpen时,我还有另一个jQuery函数来单击file1 div,但是当我单击该按钮时,就会发生切换changeProfile div的函数。 我的jQuery如下

$(document).ready(function(){
            $("#changeProfilePicture").click(function(){
                $("#changeProfile").slideToggle("slow");
            });
            $("#openOpen").click(function(){
                $("#file1").click();
            });
        });

JSFiddle http://jsfiddle.net/L7dLN/1/

任何想法如何克服这个? 提前致谢。

实际上,您只需要这样:

$("#openOpen").click(function(event){
                event.preventDefault();

                $("#file1").click();
            });

表单中按钮的默认操作/行为是提交,这是有问题的...更多: 单击<button>标记时的标准行为是什么? 会提交表格吗?

暂无
暂无

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

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