Javascript 单击按钮时如何显示div标记?
我的程序是上传一个文件,当我点击upload时,它将调用一个servlet。同一上传页面包含一些其他字段,仅当我单击上传按钮时,这些字段应显示出来。如何调用servlet以及显示剩余内容。实际上,使用servlet,我希望在同一页面上显示文件内容 这是我的密码Javascript 单击按钮时如何显示div标记?,javascript,jquery,html,Javascript,Jquery,Html,我的程序是上传一个文件,当我点击upload时,它将调用一个servlet。同一上传页面包含一些其他字段,仅当我单击上传按钮时,这些字段应显示出来。如何调用servlet以及显示剩余内容。实际上,使用servlet,我希望在同一页面上显示文件内容 这是我的密码 <form class="form-horizontal" name="regist" action="Registration" onsubmit="return validateFile((this))"
<form class="form-horizontal" name="regist" action="Registration"
onsubmit="return validateFile((this))" enctype="multipart/form-data"
method="post">
<div class="control-group" class="span12">
<label class="control-label" for="file">Please upload a
file:</label>
<div class="controls">
<input type="file" name="file"/>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Upload</button>
</div>
</div>
</form>
</div>
<div id="showFrames" style="display:none;">
<!--
hidden contents are here -->
</div>
但它不起作用。有人能帮我吗?感谢使用jQuery,我将这样做:
$('.form-horizontal').sumbit(function(e) {
if($(this).find('input[type="file"]').val().length) { //check by length
$("#showFrames").show();
} else {
alert('No file Selected');
e.preventDefault();
}
});
如果需要多个表单,最好使用表单ID
通过这种方式,您可以删除onsubmit
属性。按照下面的说明替换您的属性
Replace your as per below
<form class="form-horizontal" name="regist" action="Registration"
onsubmit="return validateFile(this)" enctype="multipart/form-data"
method="post">
<div class="control-group" class="span12">
<label class="control-label" for="file">Please upload a
file:</label>
<div class="controls">
<input type="file" name="file"/>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Upload</button>
</div>
</div>
</form>
</div>
请上传一个
文件:
上传
Replace your as per below
<form class="form-horizontal" name="regist" action="Registration"
onsubmit="return validateFile(this)" enctype="multipart/form-data"
method="post">
<div class="control-group" class="span12">
<label class="control-label" for="file">Please upload a
file:</label>
<div class="controls">
<input type="file" name="file"/>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Upload</button>
</div>
</div>
</form>
</div>