[英]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.