简体   繁体   English

jQuery函数无法运行

[英]JQuery function does not operate

I have the following HTML Structure 我有以下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>

So when I click on the div changeProfilePicture the div changeProfile slides down. 因此,当我单击div changeProfilePicture时,div changeProfile会向下滑动。 I also have another jQuery function to click the file1 div when click the button openOpen, But when I click that button the function to toggle the changeProfile div occurs. 当单击按钮openOpen时,我还有另一个jQuery函数来单击file1 div,但是当我单击该按钮时,就会发生切换changeProfile div的函数。 My Jquery as follows 我的jQuery如下

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

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

Any idea how to overcome this ? 任何想法如何克服这个? Thanks in advance. 提前致谢。

Actually, you need just this: 实际上,您只需要这样:

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

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

Default action/behavior for button in form is submit, that was problem... More: what's the standard behavior when < button > tag click? 表单中按钮的默认操作/行为是提交,这是有问题的...更多: 单击<button>标记时的标准行为是什么? will it submit the form? 会提交表格吗?

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

相关问题 如何使jQuery插件函数可以独立使用,不能在集合上运行 - How to make a jQuery plugin function callable for stand-alone use, that does not operate on a collection jQuery调整大小处理程序不会对每个元素进行操作 - jQuery resize handler does not operate on each element jQuery UI是否仅在HTML文档中运行? - Does jQuery UI operate solely within the HTML document? 为什么这个jquery each()循环不能在唯一类上运行 - Why does this jquery each() loop doesn't operate on unique classes 如何让jQuery验证成功函数以对隐藏的输入字段进行操作? - How to get jQuery validate success function to operate on a hidden input field? 我的jQuery函数只能第一次运行 - My jQuery function can only operate the first time redux thunk function 是如何运作的? 当调用 redux thunk function 时会发生什么? - How does a redux thunk function operate? What happens when a redux thunk function gets called? jQuery / HTML Operated在找到的元素上 - jQuery/HTML Operate on the found element for循环究竟是如何运行的? - How does the for loop operate exactly? 我正在尝试理解React TicTacToe教程。 他们的calculateWinner帮助程序功能如何运行? - I'm trying to make sense of the React TicTacToe tutorial. How does their calculateWinner helper function operate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM