javascript 如何使用javascript为jsp隐藏()和显示()函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21042998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide() and show() function for jsp using javascript
提问by sumit kumar gagrani
My code is
我的代码是
<script type="text/javascript">
function AddNew()
{
var partyname = $("#account_id_widget").val();
var pgroup="NA";
if(display=="none")
{
$("#log").show();
}
else
{
$('#addnew').hide();
}
}
</script>
I call this div
:
我称之为div
:
<div id="log" style="display:none;">
<%@ include file="recievable_details.jsp" %>
</div>
They're JSP which I show on my page and I call function there:
它们是我在页面上显示的 JSP,我在那里调用函数:
<sj:a id="show" button="true" onclick="AddNew()" indicator="true">AddNew</sj:a>
回答by Anup
<script type="text/javascript">
function AddNew()
{
var partyname = $("#account_id_widget").val();
var pgroup="NA";
$('#log').toggle();
}
</script>
回答by hsemarap
You could simply do this
你可以简单地这样做
<script>
function AddNew()
{
$("#log").toggle();
}
</script>
Make Sure you have included jquery in your code
确保您在代码中包含了 jquery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
or
或者
<script src="js/jquery.min.js"></script>
(if you have jquery.min.js file inside the "js" folder )
(如果“js”文件夹中有 jquery.min.js 文件)
回答by José Francisco
For hide or show any element u can use Jquery/Javascript
对于隐藏或显示任何元素,您可以使用 Jquery/Javascript
<div id="log" style="display:none;">
<%@ include file="recievable_details.jsp" %>
</div>
<div id="addNew" style="display:none;">
<%@ include file="recievable_details.jsp" %>
</div>
$("#log").hide(); or $("#log").show();
回答by Vignesh
I'm giving you a javascript function which will help you.
我给你一个 javascript 函数,它会帮助你。
toggles visibility
切换可见性
function showhide(id){
if(document.getElementById(id).className == "showhidediv_show"){
document.getElementById(id).className="showhidediv_hide";
}else{
document.getElementById(id).className="showhidediv_show";
}
}
Individual showhide functions
单独的隐藏功能
function show(id)
{
document.getElementById(id).className="showhidediv_show";
}
function hide(id)
{
document.getElementById(id).className="showhidediv_hide";
}
回答by Murali Murugesan
Probably you are missing a variable declaration for display
.
可能你是missing a variable declaration for display
。
var display=$('#log').css('display');
var display=$('#log').css('display');
<script type="text/javascript">
function AddNew()
{
var partyname = $("#account_id_widget").val();
var pgroup="NA";
var display=$('#log').css('display');
if(display=="none")
{
$("#log").show();
}
else
{
$('#addnew').hide();
}
}
</script>