我试图在点击提交按钮时显示div但是当我提交div时,会显示当前页面重新加载。在页面重新加载后,div消失了。我需要停止那个淡化。如何在javascript中完成它。 代码如下:
<div class="child" id="p2" style="display:none" data-dojo-type="dijit/TitlePane" data-dojo-props="title: 'Result'">
<% String a1=fa.getsrc();
String name=request.getParameter("sel");
String src=request.getParameter("linkrec");%>
The Selected source is ---><%=name %><br><br>
<b>The Selected operation is--><%=src %></b><br>
<b>The Source <%=name%> Has <%=src%>---><%=a1%></b>
</div>
function check()
{
usersrc=document.getElementById("sel").value;
userselect=document.getElementById("linkrec").value;
if(usersrc=="<---Select the Sources--->"|| userselect=="<---Select The Operation--->")
{
alert("Select src and records");
}
else if (usersrc=="All" && userselect=="Linkages")
{
document.getElementById('p2').style.display ='';
}</script>
答案 0 :(得分:1)
只需将 return false 添加到您的onSubmit
即可<input type="submit" name="submit" value="Save" onclick="return showdiv();"/>
** javascript **
function showdiv()
{
var error = false;
//validate your form.
if(error == true){ return true;}
else
{
//show div
return false;
}
}